3
votes

I have a Problem with Firebase Cloud Messaging: I implemented a little App with the 2 extended Services FirebaseInstanceIdService and FirebaseMessagingService.

If I start the application and send a notification via Firebase Console, I get the notification on my device. Everything works. If I open the App again, it hangs up and produces a black screen. There is no output on the Android Studio console then. I also don't get a second notification from Firebase console. Then I get a Dialog: "The Application does not react etc" After opening the app again it works fine again.

I also do not get an Token in the 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());
}
}

The only errors on the Android Studio Console is "Failed to load module descriptor class" but that is a known bug.

I hope you can help me.

Best Regards, Felix

EDIT: error message From the Firebase console:

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)
1

1 Answers

4
votes

I also do not get an Token in the Logcat (?)

onTokenRefresh() method is called when generating a new token for you. It is not called everytime you open the app. However you can get the token using FirebaseInstanceId.getInstance().getToken();

If I start the application and send a notification via Firebase Console, I get the notification on my device. Everything works. If I open the App again, it hangs up and produces a black screen.

I faced a similar issue, this generally happens if you have no or slow internet connection. No solution yet. :(