【问题标题】:Sending extras with an intent returned by getLaunchIntentForPackage() to the main activity of another app将带有 getLaunchIntentForPackage() 返回的意图的附加内容发送到另一个应用程序的主要活动
【发布时间】:2014-03-26 10:51:35
【问题描述】:

我正在尝试通过通知启动具有附加功能的应用。我得到它的启动意图:

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

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

【问题讨论】:

    标签: android android-intent


    【解决方案1】:

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

    【讨论】:

    • 试试"obj =getIntent().getSerializableExtra("test");"
    猜你喜欢
    • 1970-01-01
    • 2020-04-17
    • 1970-01-01
    • 2017-01-08
    • 1970-01-01
    • 2017-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多