android.content.ActivityNotFoundException : Intent {act = android.intent.action.VIEW dat = PendingIntent {}를 처리 할 활동이 없습니다.

Aug 17 2020

PendingIntent를 사용하여 내 앱에서 다른 앱을 실행하려고합니다. 다른 앱의 보류중인 의도 값을 가져 와서 수행합니다 (문자열 유형에 보류중인 의도 값이 있음).

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 Process : com.example.alimseolap1, PID : 4503 android.content.ActivityNotFoundException : No Activity found to handle Intent android.app.Instrumentation.checkStartActivityResult (Instrumentation.java:2018)의 {act = android.intent.action.VIEW dat = PendingIntent {78fb01 : android.os.BinderProxy@b9c2b85}} 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$com.android.internal.os.ZygoteInit.main (ZygoteInit.java:965)의 MethodAndArgsCaller.run (RuntimeInit.java:494)

무엇이 문제일까요?

답변

DavidWasser Aug 18 2020 at 16:34

PendingIntenta를 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.