У меня проблема с Firebase Cloud Messaging: я реализовал небольшое приложение с двумя расширенными службами FirebaseInstanceIdService и FirebaseMessagingService.
Если я запускаю приложение и отправляю уведомление через Firebase Console, я получаю уведомление на своем устройстве. Все работает. Если я снова открою приложение, оно зависнет и выйдет черный экран. Тогда в консоли Android Studio нет вывода. Я также не получаю второго уведомления от консоли Firebase. Затем я получаю диалоговое окно: «Приложение не реагирует и т. Д.». После повторного открытия приложения оно снова работает нормально.
Я также не получаю токен в Logcat (?)
Firebase InstanceIdService:
public class InstanceIdService extends FirebaseInstanceIdService
{
private static final String TAG = "InstanceIdService";
@Override
public void onTokenRefresh()
{
String token = FirebaseInstanceId.getInstance().getToken();
Log.e(TAG, "!!!!!!!!!!!!!!!!!! Got token: " + token);
}
}
FirebaseMessagingService:
public class MyFirebaseMessagingService extends FirebaseMessagingService
{
@Override
public void onMessageReceived(RemoteMessage remoteMessage)
{
sendNotification(remoteMessage);
}
public void sendNotification(RemoteMessage remoteMessage)
{
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setContentTitle(remoteMessage.getFrom())
.setContentText(remoteMessage.getNotification().getBody())
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
}
Единственная ошибка в консоли Android Studio - «Не удалось загрузить класс дескриптора модуля», но это известная ошибка.
Я надеюсь, что вы можете мне помочь.
С уважением, Феликс
РЕДАКТИРОВАТЬ: сообщение об ошибке Из консоли Firebase:
Exception java.lang.RuntimeException: Parcel android.os.Parcel@4215be98: Unmarshalling unknown type code 1936206469 at offset 68
android.os.Parcel.readValue (Parcel.java:2087)
android.os.Parcel.readArrayMapInternal (Parcel.java:2321)
android.os.Bundle.unparcel (Bundle.java:249)
android.os.Bundle.getString (Bundle.java:1118)
com.google.firebase.messaging.FirebaseMessagingService.zzT ()
com.google.firebase.messaging.FirebaseMessagingService.zzm ()
com.google.firebase.iid.zzb$2.run ()
java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1112)
java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:587)
java.lang.Thread.run (Thread.java:841)