3

i want to show MY GCM notifications to users when my app is closed or cleared from cache memory, below is my code its working only when app is open but not running in background:

public function send_notification($registatoin_ids, $message) {
    include_once 'dbconfig.php';
    // Set POST variables
    $url = 'https://android.googleapis.com/gcm/send';
    $fields = array(
        'registration_ids' => $registatoin_ids,
        'data' => $message,
    );

The smartphone doesn't see any services in my app. Here is a screenshot where you can compare my app with others like whatsapp: enter image description here

Below is my Manifest part about GCM:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.app.path" >    

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
 <!-- ... other permissions -->

<permission
    android:name="my.app.path.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<uses-permission android:name="my.app.path.permission.C2D_MESSAGE" />

<application
    ...>
     <!-- ... activites... -->

    <receiver
        android:name="com.google.android.gms.gcm.GcmReceiver"
        android:exported="true"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="my.app.path" />
        </intent-filter>
    </receiver>      

    <service
        android:name=".MyGcmListener"
        android:exported="false"
        android:enabled="true" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        </intent-filter>
    </service>

</application>

</manifest>

I want to show notifications like whatsApp.

Cœur
  • 37,241
  • 25
  • 195
  • 267
amit gupta
  • 1,282
  • 2
  • 20
  • 36
  • 2
    1) migrate to FCM 2) read http://stackoverflow.com/questions/37876257/push-notification-works-incorrect-when-app-is-on-background-or-not-running/37876727#37876727 – Tim Jul 11 '16 at 09:52
  • whether its not possible without FCM ? i don't know any thing regarding FCM – amit gupta Jul 11 '16 at 09:57
  • check all type of user permission & permission to using this link http://stackoverflow.com/questions/38422551/gcm-push-notification-not-revived/38423390#38423390 – Hardik Parmar Jul 20 '16 at 12:07

1 Answers1

0

Have you tried if it does help to set the priority to high when sending messages?

Set to High priority allowing the GCM service to wake a sleeping device when possible and open a network connection to your app server. Apps with instant messaging, chat, or voice call alerts, for example, generally need to open a network connection and make sure GCM delivers the message to the device without delay. Set high priority only if the message is time-critical and requires the user’s immediate interaction, and beware that setting your messages to high priority contributes more to battery drain compared to normal priority messages.

Android Enthusiast
  • 4,826
  • 2
  • 15
  • 30
  • 1
    I have tried this solution to put High priority option while sending messages but its not solved my problem – amit gupta Jul 14 '16 at 10:26