11

I am trying to make a GCM client, registration is fine. I am also successfully sending messages from server. However, the client does not start the intent. It says

09-30 08:39:59.795: W/GTalkService(4667): [DataMsgMgr] broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE cat=[dol.framework] (has extras) }

My Intent

public class GCMService extends IntentService{

    public GCMService(String name) {
        super("GCMService");
    }

    protected void onHandleIntent(Intent intent) {
        Bundle extras = intent.getExtras();
        String messageType = gcm.getMessageType(intent);
        android.util.Log.i("hi","test");
        if (!extras.isEmpty()) {

            if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
                Logger.logInUI(tag, "Received: " + extras.toString());
            }
        }
        GCMReceiver.completeWakefulIntent(intent);
    }
}

And my receiver

public class GCMReceiver extends WakefulBroadcastReceiver {
    public void onReceive(Context context, Intent intent) {
        ComponentName comp = new ComponentName(context.getPackageName(),
                GCMService.class.getName());
        startWakefulService(context, (intent.setComponent(comp)));
        Logger.log("hi","eetett");
        setResultCode(Activity.RESULT_OK);
    }
}

And finally my manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="dol.framework"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

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

    <permission android:name="dol.framework.gcm.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="dol.framework.gcm.permission.C2D_MESSAGE" />


    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:name="dol.framework.widget.DolApplication"
        android:label="Dol Framework"
        android:theme="@style/AppTheme" >
        <activity
            android:name="dol.framework.activity.DebugActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <receiver
            android:name="dol.framework.GCMReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <category android:name="dol.framework" />
            </intent-filter>
        </receiver>

        <service android:name="dol.framework.GCMService"/>
    </application>

</manifest>

Sorry for the wall of text. Both GCMService and GCMReceiver is at top of my package (dol.framework). What am I doing wrong? Other than those, I am not doing much. Only registering the device and then I am sending a message to this device. Log prints the message at top but does nothing. Shouldn't I start service or something? I didn't see anything related on examples.

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 1
    [This related](http://stackoverflow.com/questions/11902947/broadcast-intent-callback-result-cancelled-forintent) might help. – jedwards Sep 30 '13 at 08:58

2 Answers2

6

In the permission you defined and used for GCM you have dol.framework.gcm.permission. It should be dol.framework.permission, since your app's package is dol.framework.

Eran
  • 387,369
  • 54
  • 702
  • 768
  • Thank you very much! It worked after that (I actually saw something related to permissions in logs but disregarded that, damn cost me hours) –  Sep 30 '13 at 10:25
0

Try changing the receiver bit of your manifest to this:

   <receiver
        android:name=".GCMReciever"
        android:exported="true"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <action android:name="dol.framework" />
        </intent-filter>
    </receiver>
dlee
  • 78
  • 9
  • 2
    Just a note, I'm using GCM (not C2DM), and don't need the `REGISTRATION` intent ([I also think it should be `REGISTER`, not `REGISTRATION`](https://developers.google.com/android/c2dm/)) – jedwards Sep 30 '13 at 09:46
  • Me too! The app I'm working on at the moment with that code in the manifest is working. Do you have the right library set up (ie. not the old one)? – dlee Sep 30 '13 at 09:50