Всем привет, реализовал service, который получает push'и, когда приложение свернуто, они приходят, а когда закрываешь - не приходят, это firebase cloud messaging, кто нибудь знает в чем может быть причина?
service:
public class FirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService {
private static final String TAG = "FirebaseMessagingServic";
public FirebaseMessagingService() {
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// Check if message contains a data payload.
remoteMessage.getData();
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
try {
JSONObject data = new JSONObject(remoteMessage.getData());
String jsonMessage = data.getString("extra_information");
Log.d(TAG, "onMessageReceived: \n" +
"Extra Information: " + jsonMessage);
} catch (JSONException e) {
e.printStackTrace();
}
}
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
String title = remoteMessage.getNotification().getTitle(); //get title
String message = remoteMessage.getNotification().getBody(); //get message
String click_action = remoteMessage.getNotification().getClickAction(); //get click_action
Log.d(TAG, "Message Notification Title: " + title);
Log.d(TAG, "Message Notification Body: " + message);
Log.d(TAG, "Message Notification click_action: " + click_action);
sendNotification(title, message,click_action);
}
}
@Override
public void onDeletedMessages() {
}
private void sendNotification(String title,String messageBody, String click_action) {
Intent intent;
if(click_action.equals("SOMEACTIVITY")){
intent = new Intent(this, AlbumListActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}
else if(click_action.equals("MAINACTIVITY")){
intent = new Intent(this, GreetingActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}else{
intent = new Intent(this, GreetingActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(title)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
}