如何通过Firebase控制台发送通知,包括自定义数据?

时间:2017-03-06 17:17:06

标签: android firebase android-notifications firebase-cloud-messaging firebase-notifications

我必须在通知中发送一个网址,我希望点击该通知后,Chrome会立即打开该链接。目前,当我点击通知时,它只会打开我的应用。

我需要在此代码中针对我想要的行为进行哪些更改?

private void sendNotification(String messageBody, String title) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle(title)
            .setContentText(messageBody)
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0, notificationBuilder.build());
}

0 个答案:

没有答案