我制作了FlashLight小部件。在主屏幕上,它的工作非常完美。当我将其添加为锁定屏幕小工具时,它会显示但不会通过单击(或不可点击)打开手电筒。任何人都可以让我知道,我在做什么错误?我正在使用HTC ONE m7和KITKAT更新。在此先感谢您的帮助。
以下是代码:
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
final int N = appWidgetIds.length;
for (int i=0; i<N; i++) {
int appWidgetId = appWidgetIds[i];
createWid(context,appWidgetManager,appWidgetId);
}
}
private void createWid(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
// TODO Auto-generated method stub
Intent i0 = new Intent();
i0.setAction("com.cookbook.SMSresponder.AEScreenOnOffService");
context. startService(i0);
Intent receiver = new Intent(context, FlashlightWidgetReceiver.class);
receiver.setAction("COM_FLASHLIGHT");
receiver.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetId);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, receiver, 0);
RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.activity_smsr_responder);
views.setOnClickPendingIntent(R.id.buttonWidgetStopService, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, views);
}