无法从小部件SendIntentException发送待处理的意图

编程入门 行业动态 更新时间:2024-10-26 04:19:29
本文介绍了无法从小部件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发送待处理的意图

本文发布于:2023-11-27 04:38:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636625.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:意图   部件   SendIntentException

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!