Android - Widget to Play Video (onclick trouble)
Posted
by
Josh
on Stack Overflow
See other posts from Stack Overflow
or by Josh
Published on 2012-12-16T15:39:56Z
Indexed on
2012/12/16
17:04 UTC
Read the original article
Hit count: 404
I am trying to make a simple widget that will play a movie from the sdcard when clicked on. This seems simple enough, and by following tutorials I've come up with the following code, but it seems the onclick is never setup.
Manifest:
<receiver android:name="WidgetProvider" android:label="DVD Cover">
<intent-filter>
<action
android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/appwidget_info_2x4"/>
</receiver>
Layout (widget.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/holder"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ff777777"
>
<ImageView
android:id="@+id/cover"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textColor="#000000"
/>
</LinearLayout>
appwidget.xml:
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="200dip"
android:minHeight="300dip"
android:updatePeriodMillis="180000"
android:initialLayout="@layout/widget"
>
</appwidget-provider>
WidgetProvider.java:
public class WidgetProvider extends AppWidgetProvider {
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
String movieurl = Environment.getExternalStorageDirectory().getPath() + "/Movie.mp4";
Intent notificationIntent = new Intent(Intent.ACTION_VIEW);
notificationIntent.setDataAndType(Uri.parse(movieurl), "video/*");
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,0);
// Get the layout for the App Widget and attach an on-click listener
// to the button
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
views.setOnClickPendingIntent(R.id.holder, contentIntent);
// Tell the AppWidgetManager to perform an update on the current app widget
appWidgetManager.updateAppWidget(appWidgetIds, views);
}
}
Any help would be greatly appreciated.
Thanks, Josh
© Stack Overflow or respective owner