将带有 getLaunchIntentForPackage() 返回的意图的额外内容发送到另一个应用程序的主要活动

jud*_*ira 5 android android-intent

我正在尝试通过通知启动带有附加功能的应用程序。我使用以下方法获取它的启动意图:

Intent launchIntentForApp = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
Run Code Online (Sandbox Code Playgroud)

注意:上下文是同一个应用程序本身。我正在尝试构建一个可以在我的其他应用程序中使用的库。

我通过以下方式添加了一些额外内容:

launchIntentForApp.putExtra("test", true);
Run Code Online (Sandbox Code Playgroud)

然后我为它创建一个挂起的意图,并将其添加到通知抽屉中:

PendingIntent pIntent = PendingIntent.getActivity(context, 0, launchIntentForApp, 0);
Notification n = new Notification.Builder(context)
                    .setContentTitle(notifTitle)
                    .setContentText(notifMessage)
                    .setContentIntent(pIntent)
                    .setAutoCancel(true)
                    .setStyle(new Notification.BigTextStyle()
                            .bigText(notifMessage))
                    .setSmallIcon(R.color.transparent)
                    .build();
            NotificationManager notificationManager =
                    (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.notify(0, n);
Run Code Online (Sandbox Code Playgroud)

但是,当该应用程序的 Activity 启动时,在该 Activity 的 onCreate() 中,以下内容始终返回 null:

Bundle extras = getIntent().getExtras();
Run Code Online (Sandbox Code Playgroud)

我如何向该应用程序的主要活动发送额外信息?

Vig*_*n.m -1

尝试:
Bool s=getIntent().getStringExtra("test");