我正在尝试制作一个简单的小部件,单击该小部件将播放来自 sdcard 的电影。这看起来很简单,通过遵循教程,我提出了以下代码,但似乎永远不会设置 onclick。
显现:
<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>
布局(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);
}
}
任何帮助将不胜感激。
谢谢,乔什