点击小工具

时间:2015-11-25 12:29:33

标签: android widget android-pendingintent

我正在进行小部件点击。 它的工作在背景中应用完美。 关闭应用程序后,它返回ERROR。 如果有任何解决方案,请告诉我。

 E/RemoteViews: Cannot send pending intent due to unknown exception: 
11-25 17:50:31.599 2119-2119/? E/RemoteViews: android.content.ActivityNotFoundException
11-25 17:50:31.599 2119-2119/? E/RemoteViews:     at com.android.launcher3.Launcher.startIntentSenderForResult(Launcher.java:2060)
11-25 17:50:31.599 2119-2119/? E/RemoteViews:     at android.app.Activity.startIntentSender(Activity.java:4292)
11-25 17:50:31.599 2119-2119/? E/RemoteViews:     at android.content.ContextWrapper.startIntentSender(ContextWrapper.java:390)
11-25 17:50:31.599 2119-2119/? E/RemoteViews:     at android.widget.RemoteViews$OnClickHandler.onClickHandler(RemoteViews.java:217)
11-25 17:50:31.599 2119-2119/? E/RemoteViews:     at android.widget.RemoteViews$SetPendingIntentTemplate$1.onItemClick(RemoteViews.java:495)
11-25 17:50:31.599 2119-2119/? E/RemoteViews:     at android.widget.AdapterView.performItemClick(AdapterView.java:310)
11-25 17:50:31.599 2119-2119/? E/RemoteViews:     at android.widget.AbsListView.performItemClick(AbsListView.java:1145)
11-25 17:50:31.599 2119-2119/? E/RemoteViews:     at android.widget.AbsListView$PerformClick.run(AbsListView.java:3042)
11-25 17:50:31.599 2119-2119/? E/RemoteViews:     at android.widget.AbsListView$3.run(AbsListView.java:3879)
11-25 17:50:31.599 2119-2119/? E/RemoteViews:     at android.os.Handler.handleCallback(Handler.java:739)
11-25 17:50:31.599 2119-2119/? E/RemoteViews:     at android.os.Handler.dispatchMessage(Handler.java:95)
11-25 17:50:31.599 2119-2119/? E/RemoteViews:     at android.os.Looper.loop(Looper.java:148)
11-25 17:50:31.599 2119-2119/? E/RemoteViews:     at android.app.ActivityThread.main(ActivityThread.java:5417)
11-25 17:50:31.599 2119-2119/? E/RemoteViews:     at java.lang.reflect.Method.invoke(Native Method)
11-25 17:50:31.599 2119-2119/? E/RemoteViews:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
11-25 17:50:31.599 2119-2119/? E/RemoteViews:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

现在我已将我的代码附加到widgetprovider类

private RemoteViews updateWidgetListView(Context context, int appWidgetId) {

        // which layout to show on widget
        RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
                R.layout.task_list_widget);

        // RemoteViews Service needed to provide adapter for ListView
        Intent svcIntent = new Intent(context, WidgetService.class);
        // passing app widget id to that RemoteViews Service
        svcIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        // setting a unique Uri to the intent
        // don't know its purpose to me right now
        svcIntent.setData(Uri.parse(svcIntent.toUri(Intent.URI_INTENT_SCHEME)));
        // setting adapter to listview of the widget
        remoteViews.setRemoteAdapter(appWidgetId, R.id.widget_list, svcIntent);
        // setting an empty view in case of no data
        remoteViews.setEmptyView(R.id.widget_list, R.id.txt_no_data);
        Intent startActivityIntent = new Intent(context, getClass());
//      startActivityIntent.putExtra("from", "widget");
        startActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivityIntent.setAction("list");
        PendingIntent startActivityPendingIntent = PendingIntent.getActivity(context, 0, startActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        remoteViews.setPendingIntentTemplate(R.id.widget_list, startActivityPendingIntent);
//      remoteViews.setOnClickPendingIntent(R.id.btn_widget_sos, startActivityPendingIntent);
//        Intent intent = new Intent(context, Home.class);
//        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
//        // Get the layout for the App Widget and attach an on-click listener to the button
//        remoteViews.setOnClickPendingIntent(R.id.widget_list, pendingIntent);


        return remoteViews;
    }

0 个答案:

没有答案