Android + Firebase Push Notification with locked phone

0

I have my android application that receives alerts via FCM Push Notification using the (Java) method:

@Override
public void onMessageReceived(RemoteMessage remoteMessage)

My conflict is that I am not making the screen (Activity) that opens when the alarm arrives, can be shown not only with the application open, but also with the cell phone blocked ; that skips the entry pattern to the cell phone and allows you to work with that alert quickly.

Until now try the variants of uploading the priority to the maximum with the NotificationBuilder, but there is no case ...

NotificationManager.IMPORTANCE_HIGH

I can not get him to skip the cell phone lock.

Thank you very much for any comments

    
asked by Damian A Gonzalez 28.11.2018 в 15:33
source

1 answer

0

I told you that the method:

@Override
public void onMessageReceived(RemoteMessage remoteMessage)

This is done to intercept the push notifications when your application is open, as it says in the Firebase documentation:

  

Notification messages sent when the app is in the background . In this case, the notification is delivered to the device's system tray. When a user presses a notification, it opens the application selector by default.

     

Messages with notification and data payloads, both in the foreground and in the second . In this case, the notification is delivered to the system tray of the device and the data load is delivered in the additional ones of the intent of your initiating activity.

In summary, when your application is in the foreground, you can intercept the push (or not) with onMessageReceived, otherwise the Android tray gets it.

Solution What you should do is send the necessary metadata from the server, for example:

  var message = {
  data: {
    score: '850',
    time: '2:45'
  },
  topic: topic
};

That information will arrive to your device through an Intent in the first screen you have, you can capture it in the following way (the code below should print the values you sent from Firebase):

if (getIntent().getExtras() != null) {
    for (String key : getIntent().getExtras().keySet()) {
        String value = getIntent().getExtras().getString(key);
        Log.d(TAG, "Key: " + key + " Value: " + value);
    }
}

I hope it has helped you, regards.

    
answered by 16.12.2018 в 17:38