Notification, extras передать из Service
Ребят, сдаюсь! Подскажите плз, курю интернет несколько дней, перепробовал все описанное, не работает. Задача: при нажатии на уведомление мне нужно открыть нужный фрагмент. Чтобы открыть нужный фрагмент, нужно из сервиса передать имя нужного фрагмента. Не получается передать параметры extras в Activity, они всегда приходят null.
Вырезка кода из службы:
public class ServiceFirebaseCloudMessaging extends FirebaseMessagingService
{
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Intent intent = new Intent(getApplicationContext(), ActivityListMeetingsTb.class);
intent.putExtra("fragmentName", "fragmentListChats");
intent.putExtra("1", "1");
Bundle bundle = new Bundle();
bundle.putString("fragmentName", "fragmentListChats");
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(getApplicationContext());
stackBuilder.addParentStack(ActivityListMeetingsTb.class);
stackBuilder.addNextIntent(intent);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), (int) System.currentTimeMillis(), intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext(), "RendChat")
.setSmallIcon(R.drawable.ic_outline_message_24)
.setContentTitle(remoteMessage.getNotification().getTitle())
.setContentText(remoteMessage.getNotification().getBody())
.setAutoCancel(true)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
Вырезка из манифеста:
<activity android:name=".ActivityListMeetingsTb" android:launchMode="singleTask">
<intent-filter>
<action android:name="Open_ActivityListMeetingsTb" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Ловлю параметры в Activity:
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
String str = intent.getStringExtra("fragmentName");
String str2 = getIntent().getStringExtra("1");
Bundle extras = intent.getExtras();
if (intent.getExtras().get("fragmentName") != null) {
String str3 = intent.getStringExtra("fragmentName");
String str4 = getIntent().getStringExtra("fragmentName");
}
}
Вырезка из кода при отправке уведомления, передаю click_action:
json.put("to", partnerInfo.getToken());
JSONObject info = new JSONObject();
info.put("title", "Сообщение"); // Notification title
info.put("body", "У вас есть новое сообщение"); // Notification body
info.put("click_action", "Open_ActivityListMeetingsTb");
json.put("notification", info);
Все вроде по книге проделываю, нужного результата нет. Вычитал альтернативный способ, использовать компонент Navigation, ну пока не знаю что это и стоит ли вникать в него. Ребят, мозговой штурм, любые наводки, любые мысли, излагайте, плз.