1

So, I have this really weird issue with GCM on devices running on lower versions of android. I have an android library project with GCM enabled. I export it as a jar and then include it in a test application. It works fine with devices and emulator for api level 17 and devices get registered successfully but it doesn't work below that. Now here is the weird part: If i run the library project as a standalone project, it works fine on all devices including api level 10. Does any one has any idea of what could be the reason ?

Note: Using a library is important for me.

Edit:
This is what i get in my log cat:

    D/GCMRegistrar(505): resetting backoff for com.example.gcmtest
    V/GCMRegistrar(505): Registering app com.example.gcmtest of senders 378013620721

and no further response.

Sayed Jalil Hassan
  • 2,535
  • 7
  • 30
  • 42
  • Doesn't work? can you be a bit specific please? Do you receive any error message ? – Shobhit Puri Aug 29 '13 at 07:50
  • Try [this](http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/) code definitely helps you.... You might be missing this one ` ` – Kartheek Sarabu Aug 29 '13 at 07:50
  • @kartheek I already have these settings in my test application manifest file. – Sayed Jalil Hassan Aug 29 '13 at 07:58
  • @Shobhit let me update my question – Sayed Jalil Hassan Aug 29 '13 at 07:58
  • Where is the class that extends `GCMBaseIntentService` as far as I know this should be in the base backage – bogdan Aug 29 '13 at 08:06
  • That just shows that it is trying to set a backoff. It retries in case of a failure. Wait..Are you using the new way of getting the ID or the old way? – Shobhit Puri Aug 29 '13 at 08:14
  • @bogdan That class is inside my library project's root package and i have specified its full path inside the test project manifest file. bw if that was the issue it shouldn't work on newer devices either. – Sayed Jalil Hassan Aug 29 '13 at 08:16
  • @Shobhit Puri i am doing it like this: final String regId = GCMRegistrar.getRegistrationId(context); – Sayed Jalil Hassan Aug 29 '13 at 08:18
  • There's not enough info in your question. Please include your manifest, broadcast receiver and intent service. In addition to that, please specify what exactly fails. Does the registration fail or the receiving of the GCM messages? If the registration fails, what errors do you get? – Eran Aug 29 '13 at 14:04
  • Thank you @Eran. See my answer to this question. It would be great if you could explain why i had to do what i did to make it work. – Sayed Jalil Hassan Aug 29 '13 at 14:09

1 Answers1

3

Ok i figured it out myself. Just in case someone else faces this issue in future;
i'll try to explain what the issue was.
So i had a library project with GCM integration say com.test.gcm-library. I wanted to use this library in another application project say com.example.gcmtest. By following the accepted answer here i managed to to use the library successfully in my com.example.gcmtest project. It worked fine with API level 17 but when i tried it with api level 10, none of the GCMIntenetService methods would get called and no response would be generated as i posted in my question but i managed to fix it finally. The trick was to change the intent category for receiver in the manifest file. To be precise, i changed the receiver declaration in the manifest file of com.example.gcmtest from this:

    <receiver
        android:name="com.test.gcm-library.MyCustomBroadcastReceiver"
        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.test.gcm-library" />
        </intent-filter>
    </receiver>  

to this:

    <receiver
        android:name="com.test.gcm-library.MyCustomBroadcastReceiver"
        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.example.gcmtest" />
        </intent-filter>
    </receiver>

I don't know why but the receiver category field looked like a "dont care" condition for API 17 but for lower APIs this is what i had to do to make it work.

Community
  • 1
  • 1
Sayed Jalil Hassan
  • 2,535
  • 7
  • 30
  • 42
  • I don't know why the category makes no difference in API 17. I have an API 8 device, so it has always been important for me to define everything correctly (according to the GCM docs) in the manifest. – Eran Aug 29 '13 at 14:16
  • I had given reference to the root package of library project because it contained the custom GCM broadcast receiver and intent service definition but it seems like it looks for the host application root package. Am i right ? – Sayed Jalil Hassan Aug 29 '13 at 14:24
  • Hello @sayed.jalil can you please guide me to setup this process of receiving push notification from library project. I need help asap, thanks! – Harish Godara Feb 24 '14 at 11:21
  • @Harish you just need to add all the reference (i.e define permissions and receivers etc) in the the host application project (the one that's referring to the library project). – Sayed Jalil Hassan Feb 24 '14 at 11:43
  • I had done this but still not receiving any push, please can we chat? – Harish Godara Feb 24 '14 at 11:46
  • sure. between, did you use the new GoogleCloudMessaging api (that comes with SDK) or the old GCM jar file ? and also it would be better if you could post your manifest file – Sayed Jalil Hassan Feb 24 '14 at 12:13
  • Can you please send me your skype id if you are using or gmail-id for chat – Harish Godara Feb 24 '14 at 12:33
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/48335/discussion-between-sayed-jalil-and-harish-godara) – Sayed Jalil Hassan Feb 25 '14 at 07:06