我需要在收到Firebase通知时打开特定活动,这是我的代码
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.i("amirhesni" , "onMessageReceived");
if (remoteMessage.getData().size() > 0) {
sendNotification(remoteMessage);
}
}
private void sendNotification(RemoteMessage remoteMessage) {
Log.i("amirhesni" , "remote message");
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra(Constants.NotificationData.TEMP_ID, remoteMessage.getData().get(Constants.NotificationData.TEMP_ID));
intent.putExtra(Constants.NotificationData.FROM_ADDRESS, remoteMessage.getData().get(Constants.NotificationData.FROM_ADDRESS));
intent.putExtra(Constants.NotificationData.TO_ADDRESS, remoteMessage.getData().get(Constants.NotificationData.TO_ADDRESS));
intent.putExtra(Constants.NotificationData.CAN_REJECT, remoteMessage.getData().get(Constants.NotificationData.CAN_REJECT));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);/*
PendingIntent pintent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);*/
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
当应用打开或恢复时,它可以正常工作,但是我需要在关闭和手机锁定时打开应用