GCM issues below Android 4 in library project

So, I have this strange problem with GCM on devices running on lower versions of Android. I have an android library project with GCM enabled. I export it to the jar and then add it to the test application. It works great with devices and emulator for api level 17, and devices register successfully, but they do not work below that. Now here's the weird part: if I run the library project as a standalone project, it works fine on all devices, including api level 10. Does anyone have any idea what could be the reason?

Note. Using the library is important to me.

Edit:
This is what I get in my den cat:

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

and no longer responds.

+1
source share
1 answer

Ok, I figured it out myself. Just in case, if someone else faces this problem in the future; I will try to explain what the problem is.
So, I had a library project with GCM integration: com.test.gcm-library . I wanted to use this library in another application project: com.example.gcmtest . Following the accepted answer here , I was able to successfully use the library 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 be called and no answer would be generated, as I posted in my question, but I managed to fix it. The trick was to change the category of intent for the recipient in the manifest file. To be precise, I changed the recipient declaration in the manifest file 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> 

:

  <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 recipient category field looked like a “not caring” condition for API 17, but for lower APIs this is what I had to do to get it working.

+3
source

Source: https://habr.com/ru/post/1246848/


All Articles