Search code examples
androidfirebasepush-notificationfirebase-cloud-messagingscreen-lock

Firebase notifications on Android phone with screen lock


We develop an android app to show Firebase notification to user. The implementation is working very well in emulator everything is works fine, no problem.

  • When install the app to my phone:
    • When the phone is unlocked, app is foreground: Message arrived, works fine
    • When the phone is unlocked, app is background: Message arrived, works fine
    • When the phone is unlocked, app is destroyed: Message arrived, works fine
    • When the phone is locked, I hear the sound of message arrived, but I can't unlock the phone! I press the power button, and nothing happening. The phone is not responding since 5-10 seconds! After that time, the screen is on but I can't do anything on it. I can't turn off the phone, can't restart. The only way to unlock is start camera by pressing twice the power button, after a few seconds the camera is showing than I can swipe out the notification. After that everything is going well with the phone.

My code is similar which is on firebase site: https://firebase.google.com/docs/cloud-messaging/android/client.

What should I do?

Thanks


Solution

  • To send normal notifications to the app using Firebase Cloud Messaging, code is not required.

    Just add the following dependencies:

    implementation 'com.google.firebase:firebase-core:17.3.0'
    implementation 'com.google.firebase:firebase-analytics:17.3.0' 
    implementation 'com.google.firebase:firebase-messaging:20.1.5'
    

    And create a new notification like this.

    enter image description here

    It looks like Your messaging service may be misbehaving.. or check if you have latest dependencies installed.