如何解决android.content.ActivityNotFoundException:未找到处理意图的活动{act = android.intent.action.VIEW dat = PendingIntent {}
我正在尝试使用PendingIntent从我的应用程序执行另一个应用程序。我得到其他应用程序的待定Intent值并执行此操作(我得到String类型的待定Intent值)
public class NotificationCrawlingService extends NotificationListenerService {
AppDatabase appDatabase;
WordDatabase wordDatabase;
NotificationDatabase notificationDatabase;
Context context;
PackageManager pm;
NotificationEntity ne;
AllFragment allFragment;
RecyclerViewAdapter rv;
List<NotiData> notiData;
NotificationEntity noti;
Notification notification;
@Override
public int onStartCommand(Intent intent,int flags,int startId) {
return super.onStartCommand(intent,flags,startId);
}
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
super.onNotificationPosted(sbn);
context = getApplicationContext();
appDatabase = AppDatabase.getAppDatabase(context);
wordDatabase = WordDatabase.getWordDatabase(context);
notificationDatabase = NotificationDatabase.getNotificationDatabase(context);
pm = context.getPackageManager();
notification = sbn.getNotification();
Bundle extras = notification.extras;
String pakage_name = sbn.getPackageName();
String app_name = findApp_name(pakage_name);
PendingIntent pendingIntent = notification.contentIntent;
Intent intent1 = new Intent(Intent.ACTION_VIEW,Uri.parse(pendingIntent));
startActivity(intent1);
2020-08-17 16:29:27.197 4503-4503 / com.example.alimSEOlap1 E / AndroidRuntime:FATAL EXCEPTION:main 流程:com.example.alimSEOlap1,PID:4503 android.content.ActivityNotFoundException:找不到用于处理Intent的活动{act = android.intent.action.VIEW dat = PendingIntent {78fb01:android.os.BinderProxy@b9c2b85}} 在android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2018) 在android.app.Instrumentation.execStartActivity(Instrumentation.java:1673) 在android.app.Activity.startActivityForResult(Activity.java:4689) 在androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:676) 在androidx.core.app.ActivityCompat.startActivityForResult(ActivityCompat.java:234) 在androidx.fragment.app.FragmentActivity.startActivityFromFragment(FragmentActivity.java:791) 在androidx.fragment.app.FragmentActivity $ HostCallbacks.onStartActivityFromFragment(FragmentActivity.java:933) 在androidx.fragment.app.Fragment.startActivity(Fragment.java:1185) 在androidx.fragment.app.Fragment.startActivity(Fragment.java:1173) 在com.example.alimSEOlap1.views.Fragment.AllFragment $ 2.onReceive(AllFragment.java:170) 在androidx.localbroadcastmanager.content.LocalbroadcastManager.executePendingbroadcasts(LocalbroadcastManager.java:313) 在androidx.localbroadcastmanager.content.LocalbroadcastManager $ 1.handleMessage(LocalbroadcastManager.java:121) 在android.os.Handler.dispatchMessage(Handler.java:106) 在android.os.Looper.loop(Looper.java:214) 在android.app.ActivityThread.main(ActivityThread.java:7050) 在java.lang.reflect.Method.invoke(本机方法) 在com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:494) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
可能是什么问题?
解决方法
您不能像这样将PendingIntent
转换为Uri
。代替:
PendingIntent pendingIntent = notification.contentIntent;
Intent intent1 = new Intent(Intent.ACTION_VIEW,Uri.parse(pendingIntent));
startActivity(intent1);
您这样做:
PendingIntent pendingIntent = notification.contentIntent;
pendingIntent.send();
这将启动包裹在Intent
中的PendingIntent
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。