When sending Push Notifications to devices on Android O when the app is in the background, the System UI crashes and gets stuck in an endless loop. The only way to fix it is to try and reboot it and sometimes it is corrupting the phone.
Lower versions of Android have no issues with foreground or background apps. Oreo devices work fine when the app is foregrounded.
here is the message service in the manifest:
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="@string/default_notification_channel_id" />
<service
android:name=".Services.MessageService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
here is the message service:
public class MessageService extends FirebaseMessagingService {
private static final String TAG = "MessageService";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Log.d(TAG, "From: " + remoteMessage.getFrom());
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
}
if(remoteMessage.getNotification() != null){
Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
sendNotification(remoteMessage.getNotification().getBody());
}
}
private void sendNotification(String messageBody) {
Intent intent = new Intent(this, HomeScreen.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
String channelId = getString(R.string.default_notification_channel_id);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.drawable.ic_flight_takeoff_black_24dp)
.setContentTitle("FCM Message")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
}
There are no crash logs or anything in logcat because it is not getting into the app.
Any help would be greatly appreciated. Please let me know if you would like to see any other files of lines of code. Thanks in advance.
I found the answer finally. You need to make sure that you are specifying a non-adaptive icon in the meta-data or else it crashes Android O devices.
This should be added to the documentation so that other people can avoid this problem, as I have been messing with it for some time now.
Thanks for following up @lexicalninja
@kroikie could you take a look at this
Thank you all. Everything is working beautifully now.
Just an update, we are tracking this issue internally. We can reproduce under certain conditions, looking for the fastest way to fix this bug.
Just to be clear, the issue is an Oreo problem and not in the Firebase code. Oreo system can't inflate the adaptive icons and if you have an adaptive icon as your launcher or for something else and set that as the default icon for messaging, Oreo System UI crashes. Earlier version of Android will inflate them just fine.
There probably only needs to be something in the docs to highlight this issue until core Android O is patched for this issue. Thanks, again!
@lexicalninja it's actually a combination of a bunch of problems!
AndroidManifest but it was not doing enough checks to see if the launcher icon is appropriate.We're definitely going to get out a temporary fix and some docs soon, stay tuned and thanks for your input.
Gross. Glad to be of service before Oreo is on a ton of devices. Go ahead and close this when you think it is good and let me know if you need anything else.
@lexicalninja good news! This is now going to be fixed in two ways:
As there's nothing more I can do in the context of quickstart-android I am going to close this issue.
Thanks everyone!
@lexicalninja I have this issue too on my Lg G5 with Oreo 8.0 and LG doesnt offer any updates to 8.1 or 9. Is there a way to work around this somehow?I get this loop freeze issue randomly every 2-3 days, and I dont know which app it is causing it. It seems to be Whatsapp or SMS notifications while the phone is idling with screen off, but not always. Would a factory reset help to wipe those broken symbols stored somewhere causing this issue?
Most helpful comment
I found the answer finally. You need to make sure that you are specifying a non-adaptive icon in the meta-data or else it crashes Android O devices.
https://android.jlelse.eu/how-to-upgrade-your-app-to-android-oreo-and-avoid-a-factory-reset-f85e34767a09
This should be added to the documentation so that other people can avoid this problem, as I have been messing with it for some time now.