Push-уведомления Firebase - как изменить место назначения активности? - PullRequest
0 голосов
/ 02 октября 2019

У меня есть push-уведомление, которое указывает, что видео было успешно загружено. То, что я хочу, - это изменить назначение действия для щелкающего уведомления, сейчас оно переходит к моей MainActivity, но я не могу понять, как его изменить.

У меня есть класс FirebaseMessagingService из документации, но я не понимаю, куда мне ставить намерение, потому что кажется, что я никогда не достигну этого места -


public class MyFirebaseMessagingService extends FirebaseMessagingService {

    public static final String RECEIVED_FCM_ACTION = "com.onemdtalent.app.RECEIVED_FCM_ACTION";

    public static final String BD_KEY_BODY = "BD_KEY_BODY";

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        // [START_EXCLUDE]
        // There are two types of messages data messages and notification messages. Data messages are handled
        // here in onMessageReceived whether the app is in the foreground or background. Data messages are the type
        // traditionally used with GCM. Notification messages are only received here in onMessageReceived when the app
        // is in the foreground. When the app is in the background an automatically generated notification is displayed.
        // When the user taps on the notification they are returned to the app. Messages containing both notification
        // and data payloads are treated as notification messages. The Firebase console always sends notification
        // messages. For more see: https://firebase.google.com/docs/cloud-messaging/concept-options
        // [END_EXCLUDE]

        Timber.tag("remoteMessage").d(remoteMessage.getData().toString());

        //String image = remoteMessage.getData().get("image");

        Timber.d("onMessageReceived: %s", remoteMessage.getFrom());
        // Check if message contains a notification payload.
        if (remoteMessage.getNotification() != null) {

            String body = remoteMessage.getNotification().getBody();
            Timber.d("Message Notification Body: %s", body);
            // broadcast
            Intent localIntent = new Intent(RECEIVED_FCM_ACTION);
            localIntent.putExtra(BD_KEY_BODY, body);
            LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent);
        }
    }



}


Ответы [ 2 ]

1 голос
/ 02 октября 2019

Установите активность в пункте назначения, используя Pendingintent.

    Intent intent = new Intent(this,YourActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

в вашем конструкторе уведомлений задайте намерение содержимого, подобное этому

    builder.setContentIntent(pendingIntent);
0 голосов
/ 02 октября 2019

Вы получите данные о намерениях в своей MainActivity, вы можете взять данные о намерениях и запустить RedirectActivity с данными о намерениях.

получить данные о намерениях в своей деятельности по перенаправлению и проанализировать ваши данные. Надеюсь, это сработает для вас.

Поместите этот тип кода в свой MainActivity.class

Intent intent = new Intent(this,RedirectActivity.class);
intent.putExtra("data",getIntent());
startActivity(intent1);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...