Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在onReceive中未找到随按钮单击发送的WidgetProvider意图附加_Android_Widget_Android Intent_Broadcastreceiver - Fatal编程技术网

Android 在onReceive中未找到随按钮单击发送的WidgetProvider意图附加

Android 在onReceive中未找到随按钮单击发送的WidgetProvider意图附加,android,widget,android-intent,broadcastreceiver,Android,Widget,Android Intent,Broadcastreceiver,我试图检测小部件按钮被点击的时间,但是Intent附加项没有显示在onReceive方法中 每次单击都会调用onReceive,但没有显示我的Intentextra 我的代码如下:我只在更新时连接切换按钮,所以不确定这是否正确。即使我设置了此选项,也不会显示任何附加项,并且类别为null onUpdate(上下文等): RemoteViews remoteViews = new RemoteViews(context.getPackageName(),

我试图检测小部件按钮被点击的时间,但是
Intent
附加项没有显示在
onReceive
方法中

每次单击都会调用
onReceive
,但没有显示我的
Intent
extra

我的代码如下:我只在更新时连接切换按钮,所以不确定这是否正确。即使我设置了此选项,也不会显示任何附加项,并且类别为
null

onUpdate(上下文等):

RemoteViews remoteViews = new RemoteViews(context.getPackageName(), 
                                R.layout.my_widget);

Intent buttonIntent = new Intent(context, MyWidgetProviderClass.class);
buttonIntent.setAction(ACTION_WIDGET_RECEIVER);
buttonIntent.putExtra("BUTTON_CLICKED", "buttonClick");
buttonIntent.putExtra("BUTTON",899);

PendingIntent muPendingIntent = PendingIntent.getBroadcast(context, 0, 
                                        buttonIntent, 
                                        PendingIntent.FLAG_CANCEL_CURRENT);
buttonIntent.addCategory("buttonclick");
remoteViews.setOnClickPendingIntent(R.id.ToggleImageButton, myPendingIntent);
appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
intent.getIntExtra("BUTTON",-1);    ---> 1
intent.getCategories()   --- > null
onReceive():

RemoteViews remoteViews = new RemoteViews(context.getPackageName(), 
                                R.layout.my_widget);

Intent buttonIntent = new Intent(context, MyWidgetProviderClass.class);
buttonIntent.setAction(ACTION_WIDGET_RECEIVER);
buttonIntent.putExtra("BUTTON_CLICKED", "buttonClick");
buttonIntent.putExtra("BUTTON",899);

PendingIntent muPendingIntent = PendingIntent.getBroadcast(context, 0, 
                                        buttonIntent, 
                                        PendingIntent.FLAG_CANCEL_CURRENT);
buttonIntent.addCategory("buttonclick");
remoteViews.setOnClickPendingIntent(R.id.ToggleImageButton, myPendingIntent);
appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
intent.getIntExtra("BUTTON",-1);    ---> 1
intent.getCategories()   --- > null

尝试
FLAG\u UPDATE\u CURRENT
而不是
FLAG\u CANCEL\u CURRENT

此外,您的代码可能有输入错误:您有
mupendingent
而不是
mypendingent

另外,请不要使用
按钮单击
作为类别。请为它命名名称(例如,
com.something.whatever.button单击
),或将其删除,因为我不确定您为什么需要它


演示一个应用程序小部件,该小部件在点击时触发自身更新,并带有一个额外的(用于提供应用程序小部件ID)。

Android显然不喜欢重复使用名称ACTION\u widget\u RECEIVER并删除这些参数。仅为切换按钮创建了另一个操作,已在清单中注册,现在参数显示。

我发现,如果用于创建挂起的意图的意图中已有任何附加内容,则新意图的附加内容将被忽略。例如,如果您按照Android文档中的示例构建这样的小部件

Intent toastIntent = new Intent(context, StackWidgetProvider.class);
toastIntent.setAction(StackWidgetProvider.TOAST_ACTION);
toastIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
PendingIntent toastPendingIntent = PendingIntent.getBroadcast(context, 0, toastIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
rv.setPendingIntentTemplate(R.id.stack_view, toastPendingIntent);
然后排队

toastIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);

将防止你的新意图的附加内容粘住。我删除了该行,我的新意图起了作用。

我正在寻找一种方法,以查看该按钮是否在onReceive中被实际单击。他们仍然没有出现在onReceive中。这就像是一个不同的意图,没有任何额外的东西?我需要一种方法来看看是哪个按钮触发的,因为接收得到了其他的意图。我确实尝试过标记“更新”当前而没有效果,只是没有额外的东西出现或者我做过的任何设置。@Androider:我能告诉你的是,我链接到的代码工作正常。由你来决定你的方法和我的方法有什么不同。事实上我也有同样的问题。临时演员在某个时刻被分离。他们第一次工作,但是没有额外的工作。