Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Android is not receiving FCM push notification?

I am working on an Android project and trying to receive Push Notifications using FCM. I implemented everything just like it is described here, on official documentation of FCM.

I tested my work by sending demo notification from Firebase console and it worked. I used web key in my Django website and it sends notification to FCM servers and my Android app receives is properly. But there is a problem with that. App only receives notification when it is connected to Android Studio and debug app is installed and running. If I exit from debug app and try, it doesn't receive it. I changed priority to hight, added content_available = true but still not working properly.

I checked the error log in Android Studio and found this,

W/GCM-DMM: broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE flg=0x10000000 pkg=com.app.android (has extras) }

I think GCM is playing part in the scene, and I don't know what to do to solve this error because I am not working with GCM code at all as everything is migrated to FCM. Can anyone tell me what else I need to do to start receiving push notification when my device is not connected with Android Studio and debug app is not running?

NOTE: My django code works fine and I see success message in response from FCM server.

Thanks.

like image 966
Amit Pandya Avatar asked Mar 04 '17 19:03

Amit Pandya


People also ask

How do I get push notifications on Android?

Turn on notifications for Android devicesTap More on the bottom navigation bar and select Settings. Tap Turn on notifications. Tap Notifications. Tap Show notifications.

How does FCM work on Android?

The FCM backend receives the message request, generates a message ID and other metadata, and sends it to the platform specific transport layer. When the device is online, the message is sent via the platform-specific transport layer to the device. On the device, the client app receives the message or notification.


1 Answers

add this to service manifest :

android:enabled="true"
android:exported="true">

just like this :

     <service
        android:name=".firebase.MyFirebaseMessagingService"
        android:enabled="true"
        android:exported="true">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>
    <service
        android:name=".firebase.MyFirebaseInstanceIDService"
        android:enabled="true"
        android:exported="true">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
        </intent-filter>
    </service>
like image 169
user5962153 Avatar answered Oct 13 '22 11:10

user5962153