无论我做什么,我不能触发通过点击一个按钮上的部件东西。 下面是一些代码我写的,谁能告诉我,为什么onReceive
点击小部件按钮时不叫?
此外,我想运行按钮点击的功能...基于下面的代码做我有个好主意?
public class WidgetProvider extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
Intent intent = new Intent(context, WidgetProvider.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
views.setOnClickPendingIntent(R.id.toggleButton, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetIds[0], views);
}
@Override
public void onReceive(Context context, Intent intent) {
// why don't i get here with the button click?
Log.e("!", intent.getAction());
}
}