android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=PendingIntent{ }

huangapple go评论81阅读模式
英文:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=PendingIntent{ }

问题

我正在尝试使用 PendingIntent 从我的应用程序启动另一个应用程序。我获取其他应用程序的待定意图值,并执行以下操作(我以字符串类型获取待定意图值)

public class NotificationCrawlingService extends NotificationListenerService {
    // ...(此处省略了部分代码)

    @Override
    public void onNotificationPosted(StatusBarNotification sbn) {
        // ...(此处省略了部分代码)

        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
    Process: com.example.alimseolap1, PID: 4503
    android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=PendingIntent{78fb01: android.os.BinderProxy@b9c2b85} }
        at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2018)
        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1673)
        at android.app.Activity.startActivityForResult(Activity.java:4689)
        at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:676)
        at androidx.core.app.ActivityCompat.startActivityForResult(ActivityCompat.java:234)
        at androidx.fragment.app.FragmentActivity.startActivityFromFragment(FragmentActivity.java:791)
        at androidx.fragment.app.FragmentActivity$HostCallbacks.onStartActivityFromFragment(FragmentActivity.java:933)
        at androidx.fragment.app.Fragment.startActivity(Fragment.java:1185)
        at androidx.fragment.app.Fragment.startActivity(Fragment.java:1173)
        at com.example.alimseolap1.views.Fragment.AllFragment$2.onReceive(AllFragment.java:170)
        at androidx.localbroadcastmanager.content.LocalBroadcastManager.executePendingBroadcasts(LocalBroadcastManager.java:313)
        at androidx.localbroadcastmanager.content.LocalBroadcastManager$1.handleMessage(LocalBroadcastManager.java:121)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7050)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)

可能的问题是什么?

英文:

I am trying to execute another app from my app using PendingIntent. I get other apps' pending Intent value and do this (I got pending intent value in String type)

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);

However it won't work.
Shows this error in Log

2020-08-17 16:29:27.197 4503-4503/com.example.alimseolap1 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.alimseolap1, PID: 4503
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=PendingIntent{78fb01: android.os.BinderProxy@b9c2b85} }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2018)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1673)
at android.app.Activity.startActivityForResult(Activity.java:4689)
at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:676)
at androidx.core.app.ActivityCompat.startActivityForResult(ActivityCompat.java:234)
at androidx.fragment.app.FragmentActivity.startActivityFromFragment(FragmentActivity.java:791)
at androidx.fragment.app.FragmentActivity$HostCallbacks.onStartActivityFromFragment(FragmentActivity.java:933)
at androidx.fragment.app.Fragment.startActivity(Fragment.java:1185)
at androidx.fragment.app.Fragment.startActivity(Fragment.java:1173)
at com.example.alimseolap1.views.Fragment.AllFragment$2.onReceive(AllFragment.java:170)
at androidx.localbroadcastmanager.content.LocalBroadcastManager.executePendingBroadcasts(LocalBroadcastManager.java:313)
at androidx.localbroadcastmanager.content.LocalBroadcastManager$1.handleMessage(LocalBroadcastManager.java:121)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7050)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)

What might be the problem?

答案1

得分: 0

你不能像那样将 PendingIntent 直接转换为 Uri。而是要这样做:

PendingIntent pendingIntent = notification.contentIntent;
pendingIntent.send();

这会启动被包装在 PendingIntent 中的 Intent

英文:

You can't convert a PendingIntent into a Uri like that. Instead of:

PendingIntent pendingIntent = notification.contentIntent;
Intent intent1 = new Intent(Intent.ACTION_VIEW, Uri.parse(pendingIntent));
startActivity(intent1);

You do this:

PendingIntent pendingIntent = notification.contentIntent;
pendingIntent.send();

This launches the Intent that was wrapped in the PendingIntent.

huangapple
  • 本文由 发表于 2020年8月17日 15:38:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/63446557.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定