【发布时间】:2017-09-18 12:59:13
【问题描述】:
我想在点击通知但打开应用时打开 Play Market。 我使用 Firebase 通知。
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
showNotification(remoteMessage.getNotification().getBody());
}
private void showNotification(String message) {
String textFirebaseEn = getResources().getString(R.string.notification_text_firebase_checking);
if (message.equals(textFirebaseEn)) {
String localTitle = getResources().getString(R.string.notification_title_firebase);
String localText = getResources().getString(R.string.notification_text_firebase);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext())
.setSmallIcon(R.drawable.avatar_notification)
.setContentTitle(localTitle)
.setContentText(localText)
.setAutoCancel(true)
.setSound(defaultSoundUri);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(PLAY_MARKET));
builder.setContentIntent(PendingIntent.getActivity(getApplicationContext(), 0, intent, 0));
Notification notification = builder.build();
NotificationManager manager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(0, notification);
}
}
请告诉我哪里错了?
【问题讨论】:
-
不要使用直接市场 URI,而是创建一个空白 Activity 并将 contentIntent 重定向到该空白 Activity 并从该空白 Activity 处理您的 Play 商店重定向。
标签: android firebase push-notification notifications firebase-notifications