Push Notification not Received in android

后端 未结 3 1738
执笔经年
执笔经年 2020-12-20 05:11

I am new to push notifications and I\'m trying to send a push notification to a particular device which has already been registered to GCM service. I implemented my app acco

相关标签:
3条回答
  • 2020-12-20 05:50

    IF you could send a notification and configure a GCM so the problem should be with network. Try to look if your ports are not blocked for notification (I had similar problem - I could send but not receive notification after unlocking ports I received notifications).

    0 讨论(0)
  • 2020-12-20 05:55

    You have some errors in your manifest that only cause problems on old Android versions :

    Your packagge name is com.markattendence.markattendence.

    Therefore you should change this :

    <permission android:name="com.markattendence.markattendence.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" />
    

    To this:

    <permission android:name="com.markattendence.markattendence.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="com.markattendence.markattendence.permission.C2D_MESSAGE" />
    

    And this:

    <receiver
        android:name="com.google.android.gcm.GCMBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
    
            <!-- Receives the actual messages. -->
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <!-- Receives the registration id. -->
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
    
            <category android:name="com.markattendence.activites" />
        </intent-filter>
    </receiver>
    

    To this:

    <receiver
        android:name="com.google.android.gcm.GCMBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
    
            <!-- Receives the actual messages. -->
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <!-- Receives the registration id. -->
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
    
            <category android:name="com.markattendence.markattendence" />
        </intent-filter>
    </receiver>
    
    0 讨论(0)
  • 2020-12-20 06:05

    For sending the push to a specific device. First of all you need to pick the token from the FCM :

    String token = FirebaseInstanceId.getInstance().getToken();
    

    Then this unique token is used to send the push request from server post request. Please find the headers of the post request along with required structure of the body.

    Headers

    Content-Type     'application/json'
    Authorization    'key=(server-key)'
    

    Note: Not other than these values are allowed in headers. And here the 'server-key' is your browser key provide from FCM console.

    Body For Push Request

    {
      "data": {
        "NotificationDetailsID": 1131,
        "MessageGroup": "HR",
        "Message": "this is notification"
      },
      "to": "firebase-token-of-androidDevice"
    }
    

    This is the server side implementation and this will definitely work. As we have tested at our end. You will receive the push while the app is even closed.

    0 讨论(0)
提交回复
热议问题