android小部件不能点击,android-小部件setOnClickPendingIntent无法启动服...
好吧,我设法解决了public class WidgetProvider extends AppWidgetProvider {@Overridepublic void onUpdate(Context context, AppWidgetManager appWidgetManager,int[] appWidgetIds) {Log.e("ERROR", "onUpdate method ca
好吧,我设法解决了
public class WidgetProvider extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
Log.e("ERROR", "onUpdate method called");
final int N = appWidgetIds.length;
// Perform this loop procedure for each App Widget that belongs to this provider
for (int i=0; i
int appWidgetId = appWidgetIds[i];
// Create an Intent to launch ExampleActivity
Intent intent = new Intent(context, UpdateService.class);
PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0);
Log("Pending Intent = " + pendingIntent.toString());
// 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_layout);
views.setOnClickPendingIntent(R.id.widge, pendingIntent);
// Tell the AppWidgetManager to perform an update on the current App Widget
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
public static class UpdateService extends Service {
@Override
public void onCreate() {
.........
.........
}
// Service stuff here
}
}
我不完全确定在onEnable中这样做有什么问题.也许有人可以阐明原因.
更多推荐
所有评论(0)