有几个通知,点击通知我想转到特定活动。假设出现奖励通知,点击将转到 RewardActivity 并添加新朋友,然后单击 newFriend 通知将转到friendlistActivity,无论应用程序是在前台还是后台。
但在我的情况下,如果出现任何通知,它会转到相同的活动而不是不同的活动。
private void handleDataMessage(String noti_title,String noti_message,String noti_click_action) {
try {
Intent intent = new Intent(this, RewardActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("title", noti_title);
ByteArrayOutputStream _bs = new ByteArrayOutputStream();
//image.compress(Bitmap.CompressFormat.PNG, 50, _bs);
//intent.putExtra("img", image);
intent.putExtra("msg", noti_message);
intent.putExtra("click_action", noti_click_action);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new
NotificationCompat.Builder(this, "Default")
//.setLargeIcon(R.mipmap.ic_launcher)/*Notification icon image*/
.setSmallIcon(R.mipmap.ic_launcher)
//.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(image))/*Notification with Image*/
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setPriority(Notification.PRIORITY_HIGH)
.setChannelId("Default")
.setVibrate(new long[]{1000, 1000})
.setContentIntent(pendingIntent);
notificationBuilder.setContentTitle(noti_title);
notificationBuilder.setContentText(noti_message);
notificationBuilder.setAutoCancel(true);
NotificationManager notificationManager …
Run Code Online (Sandbox Code Playgroud) 当应用程序在后台或被杀死 onRecive onMessageReceived() 未调用时,我在通知中只收到 json。下面是我的服务类
public class AppFireBaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "From: " + remoteMessage.getFrom());
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
sendNotification(remoteMessage.getNotification().getTitle(), remoteMessage.getNotification().getBody());
Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
}
// Check if message contains a data payload.
else if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
sendNotification(remoteMessage.getData().get("title"), remoteMessage.getData().get("body"));
}
}
@Override
public void …
Run Code Online (Sandbox Code Playgroud)