Cannot send pending intent from widget, SendIntentException(无法从小部件发送待处理的意图,SendIntentException)
本文介绍了无法从小部件发送待处理的意图,SendIntentException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用以下代码从我的小部件发送广播:
I want to send a broadcast from my widget with this code:
for (int i = 0; i < N; i++) {
int appWidgetId = appWidgetIds[i];
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
Intent x = new Intent();
if (isActive == true) {
views.setImageViewResource(R.id.w_image, R.drawable.w_bild);
x.setAction("de.bulling.smstalk.DISABLE");
} else {
views.setImageViewResource(R.id.w_image, R.drawable.w_bild_off);
x.setAction("de.bulling.smstalk.ENABLE");
}
PendingIntent z = PendingIntent.getBroadcast(context, 0, x, PendingIntent.FLAG_ONE_SHOT);
views.setOnClickPendingIntent(R.id.w_image, z);
appWidgetManager.updateAppWidget(appWidgetId, views);
}
但是,我收到此错误:
E/RemoteViews(18176): Cannot send pending intent:
E/RemoteViews(18176): android.content.IntentSender$SendIntentException
E/RemoteViews(18176): at android.app.ContextImpl.startIntentSender(ContextImpl.java:640)
E/RemoteViews(18176): at android.widget.RemoteViews$SetOnClickPendingIntent$1.onClick(RemoteViews.java:157)
E/RemoteViews(18176): at android.view.View.performClick(View.java:2408)
E/RemoteViews(18176): at android.view.View$PerformClick.run(View.java:8816)
E/RemoteViews(18176): at android.os.Handler.handleCallback(Handler.java:587)
E/RemoteViews(18176): at android.os.Handler.dispatchMessage(Handler.java:92)
E/RemoteViews(18176): at android.os.Looper.loop(Looper.java:123)
E/RemoteViews(18176): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/RemoteViews(18176): at java.lang.reflect.Method.invokeNative(Native Method)
E/RemoteViews(18176): at java.lang.reflect.Method.invoke(Method.java:521)
E/RemoteViews(18176): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
E/RemoteViews(18176): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
E/RemoteViews(18176): at dalvik.system.NativeStart.main(Native Method
这是什么原因?你有什么主意吗?谢谢,马克
What's the reason for this? Do you have any idea? Thanks, Marc
/edit:我找到了答案:必须是 Intent x = new Intent(context, WidgetClass.class);
/edit: I found the answer: It has to be Intent x = new Intent(context, WidgetClass.class);
推荐答案
我找到了答案:一定是 Intent x = new Intent(context, WidgetClass.class);
I found the answer: It has to be Intent x = new Intent(context, WidgetClass.class);
这篇关于无法从小部件发送待处理的意图,SendIntentException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:无法从小部件发送待处理的意图,SendIntentException
基础教程推荐
猜你喜欢
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01