我正试图使用PendingIntent从我的应用程序中执行另一个应用程序。我获取其他应用程序的挂起的Intent值并执行此操作(我在字符串类型中获得挂起的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:致命异常:main流程:com.example.alimseolap1,PID:4503android.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.ActivityCompt.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.executeEndingBroadcasts(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(ActivityThreads.java:7050(位于java.lang.reflect.Method.ioke(本机方法(网址:com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494(网址:com.android.internal.os.ZygoteInit.main(ZygoteNit.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();
这将启动封装在PendingIntent
中的Intent
。