【发布时间】:2017-02-16 08:43:33
【问题描述】:
我知道这个问题似乎是重复的,但是为了我的要求,我在网上搜索了很多帖子,但没有任何对我有用。
我的要求
我正在使用 Firebase 来获取推送通知。打开应用程序时意味着一切正常,但我的问题是,如果收到任何推送通知,应用程序处于后台/关闭意味着我想在单击该通知时打开特定的活动或片段,但它总是打开启动器/主要活动。
为此,我尝试了以下场景
场景 1
使用bundle 将通知数据从FirebaseMessagingService 传输到启动器/主活动,并根据我重定向到特定活动/片段的捆绑数据
场景 2
通过使用Sharedpreference
场景 3
通过使用intent.putExtra
按照上述情况,当应用打开时一切正常,但如果我的应用关闭意味着它总是重定向到主/启动器活动
我的代码
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra("reqTo", messageBody);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(title)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
那么,有没有人知道在应用关闭时单击 Firebase 推送通知时如何打开特定的活动/片段。
【问题讨论】:
-
请检查我的回答。如果你仍然有问题给我回复我会帮助你
标签: android firebase push-notification android-notifications firebase-cloud-messaging