Появилась необходимость реализовать push уведомления.
Прописал в манифесте сервис:
<service
android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
Сам класс у меня выглядит так:
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
sendNotification(remoteMessage.getNotification().getBody());
}
private void sendNotification(String messageBody) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.icon)
.setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.mipmap.icon))
.setContentTitle(this.getString(R.string.app_name))
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
}
В чем собственно дело:
У меня устройство на котором я провожу дебаггинг приложения, на нем все успешно приходит(android marshmallow). Пробую на другом устройстве(android 4.1, 4.2.2, 5.1) на них вообще глухо. Даже когда приложение запущено, уведомления не приходят.
Подскажите, в чем проблема, ведь на моем устройстве приходит. Библиотеки, все подключены корректно. Может быть с версиями API прогадал?