В настоящее время я работаю над push-уведомлением в своем проекте. Когда отображается push-уведомление, я хочу открыть активность Mynotification, когда вы нажимаете на уведомление, но всегда открываете MainActivity, почему? Я также google и SO для этого, но не могу найти правильный ответ.Как открыть мероприятие при нажатии кнопки pushnotification?
Вот мой MyFirebaseMessagingService:
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
sendNotification(remoteMessage.getNotification().getBody());
}
private void sendNotification(String messageBody) {
Intent intent = new Intent(this, MyNotification.class);
intent.putExtra("Message",messageBody);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
0);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("Shri Sidhbali Baba")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
}
И вот мой файл манифеста:
<activity android:name=".MyNotification"
android:parentActivityName=".MainActivity">
<intent-filter>
<action android:name=".MyNotification" android:label="@string/app_name"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
Как я могу открыть Mynotification активность при нажатии ой толчок уведомления. Спасибо за ваше время ...
Не работает @Himani – Manish
добавить эту строку notificationBuilder .setContentIntent (contentIntent); –
setContentIntent (pendingIntent); это изменение в setContentIntent (contentIntent); – Manish