【发布时间】:2019-07-02 16:55:30
【问题描述】:
我的fcm点击操作有问题,收到通知后,当我点击它时,它应该打开浏览器,进入“www.google.co.in”,但是当我点击通知时,它会打开默认主活动。
这是我的 onMessageReceived() :
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "Message Data Payload:" + remoteMessage.getData());
Log.d(TAG, "Message notification body: " + remoteMessage.getNotification().getBody());
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("www.google.co.in"));
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
String channelId = getString(R.string.default_notification_channel_id);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.drawable.ic_stat_ic_notification)
.setContentTitle("FCM Message")
.setContentText("FCM MessageBody")
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// Since android Oreo notification channel is needed.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(channelId,
"Channel human readable title",
NotificationManager.IMPORTANCE_DEFAULT);
notificationManager.createNotificationChannel(channel);
}
notificationManager.notify(0, notificationBuilder.build());
}
有人知道这段代码的具体实现是什么或有什么问题吗?
提前致谢。
【问题讨论】:
标签: android firebase android-studio android-intent firebase-cloud-messaging