Reputation: 558
I'm unable to receive push notification on my app running android < 4.1
I have a real device running KITKAT 4.4.4 and works fine, but with an old device (like firmware 2.3.6) it does not work ... i tested also on 4.0.4 without luck .
I can register and unregister well on the server, i obtain the RegistrationID correctly but nothing happend when i trigger the push notification from the server to the old devices.
The only message i see in the log is :
W/GTalkService﹕ [DataMsgMgr] broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE cat=[com.metu.tracker.app] (has extras) }
I post my configuration below, so you can see the code.
this is my manifest :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.metu.tracker.app" >
<!-- Network State Permissions to detect Internet status -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Permission to save in external storage for image save (avatar) -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Permission to get fine coordinate -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- Permission to open the gallery and modify photos -->
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!-- Permission to get MAPS -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<permission
android:name="com.metu.tracker.app.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.metu.tracker.app.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- Permission GCM -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.metu.tracker.gcm.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.metu.tracker.gcm.permission.C2D_MESSAGE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<receiver
android:name=".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.metu.tracker.app" />
</intent-filter>
</receiver>
<service android:name=".GCMIntentService" />
<activity
android:name="com.metu.tracker.app.MainActivity"
android:label="@string/app_name"
android:noHistory="true">
...
This is my Receiver :
package com.metu.tracker.app;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.WakefulBroadcastReceiver;
/**
* Created by metu on 28/08/14.
*/
public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Explicitly specify that GcmIntentService will handle the intent.
ComponentName comp = new ComponentName(context.getPackageName(),
GCMIntentService.class.getName());
// Start the service, keeping the device awake while it is launching.
int FLAG_INCLUDE_STOPPED_PACKAGES = 32;
intent.addFlags(FLAG_INCLUDE_STOPPED_PACKAGES);
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}
}
This is my service :
public class GCMIntentService extends GCMBaseIntentService {
public GCMIntentService() {
super(SENDER_ID);
}
/**
* Method called on device registered
**/
@Override
protected void onRegistered(Context context, String registrationId) {
Log.i(TAG, "Device registered: regId = " + registrationId);
//displayMessage(context, "Your device registred with GCM");
//Log.d("NAME", MainActivity.name);
ServerUtilities.register(context, registrationId);
}
/**
* Method called on device un registred
* */
@Override
protected void onUnregistered(Context context, String registrationId) {
//Log.i(TAG, "Device unregistered");
displayMessage(context, getString(R.string.gcm_unregistered));
ServerUtilities.unregister(context, registrationId);
}
/**
* Method called on Receiving a new message
* */
@Override
protected void onMessage(Context context, Intent intent) {
Log.i(TAG, "Received message");
String message = intent.getExtras().getString("message");
displayMessage(context, message);
// notifies user
generateNotification(context, message);
// Release the wake lock provided by the WakefulBroadcastReceiver.
GcmBroadcastReceiver.completeWakefulIntent(intent);
...
i look already in stackoverflow, there is some useful information about this error but i cant figure out how to solve it. I need some help.
Thanks.
Upvotes: 1
Views: 2110
Reputation: 558
I found the error.
the manifest was wrong :
<!-- Permission GCM -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.metu.tracker.gcm.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.metu.tracker.gcm.permission.C2D_MESSAGE" />
my app package name is com.metu.tracker.app so the lines here was wrong, correct with :
<!-- Permission GCM -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.metu.tracker.app.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.metu.tracker.app.permission.C2D_MESSAGE" />
the BroadcastReceiver definition was wrong :
<receiver
android:name=".GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
The right name is :
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
After this changes the push notification will work.
if it doesn't work please unregister and register again ...
Upvotes: 3