I've been looking on the internet for quite a while now, but have not found the answer. I have followed the examples and tutorials: https://developers.google.com/cloud-messaging/android/client
I see there are several who have problems with this when they try to send "notification" payload, but for my app, it's only "data" payload.
gcmListner:
public class GCMPushReceiver extends GcmListenerService {
@Override
public void onMessageReceived(String from, Bundle data) {
Log.d("gcmReceiver", "something received");
String message = data.getString("message");
sendNotificasjon(message);
}
}
Manifest:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<permission android:name="com.example.myapp.permission.C2D_MESSAGE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.myapp.permission.C2D_MESSAGE"/>
<application
android:allowBackup="true"
android:icon="@drawable/app_icon"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.premission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.example.myapp"/>
</intent-filter>
</receiver>
<service android:name=".GCMPushResiver" android:exported="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
</intent-filter>
</service>
<service android:name=".GCMregistrationIntentService" android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID"/>
</intent-filter>
</service>
</application>
postman sendt:
{
"to":"SOME_TOLKEN_XXX",
"data": {
"message": "melding"
}
}
postman received:
{
"multicast_id": 73503399375464XXXX,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [
{
"message_id": "0:1471781513806225%030a2fe3f9fdXXX"
}
]
}