gpt4 book ai didi

android - 将带有 getLaunchIntentForPackage() 返回的 Intent 的额外内容发送到另一个应用程序的主要 Activity

转载 作者:太空宇宙 更新时间:2023-11-03 11:25:13 25 4
gpt4 key购买 nike

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

Intent launchIntentForApp = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());

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

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

launchIntentForApp.putExtra("test", true);

然后我为它创建一个待处理的 Intent ,并将它添加到通知抽屉:

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

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

Bundle extras = getIntent().getExtras();

如何向该应用的主要 Activity 发送额外信息?

最佳答案

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

关于android - 将带有 getLaunchIntentForPackage() 返回的 Intent 的额外内容发送到另一个应用程序的主要 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22658687/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com