GCM Intent OnRegistered service not receiving call

I created the GCM Intent service and the device successfully registered. I also get a REGISTRATION RECORD, but the OnMessage or OnRegistered methods do not receive the call.

Below the magazine I see.

07-23 06:24:23.542: V/GCMBroadcastReceiver(1168): onReceive: com.google.android.c2dm.intent.REGISTRATION 07-23 06:24:23.542: V/GCMBroadcastReceiver(1168): GCM IntentService class: com.app.demo.myApp.GCMIntentService 07-23 06:24:23.581: V/GCMBaseIntentService(1168): Acquiring wakelock 

Below is the code for OnMessage.

Can someone help me on why the call to OnRegistered or OnMessage is not called.

  public class GCMIntentService extends GCMBaseIntentService { @Override protected void onMessage(Context arg0, Intent arg1) { // TODO Auto-generated method stub Toast.makeText(getApplicationContext(), "registered", Toast.LENGTH_LONG).show(); String device_id = GCMRegistrar.getRegistrationId(this); GSLogger.Log("mess_received", device_id); } @Override protected void onRegistered(Context context, String arg1) { Toast.makeText(context, "registered", Toast.LENGTH_LONG).show(); String device_id = GCMRegistrar.getRegistrationId(this); GSLogger.Log("registered", device_id); } } 

Manifest code:

 <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="8" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.READ_CALENDAR" /> <uses-configuration android:name="android.permission.GET_ACCOUNTS"/> <uses-permission android:name="com.google.android.c2dm.permission.C2D_MESSAGE"/> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <permission android:name="com.app.demo.myApp.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="com.app.demo.myApp.permission.C2D_MESSAGE" /> 

The receiver code in the manifest:

 <receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" 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" /> <category android:name="com.app.demo.myApp" /> </intent-filter> </receiver> <service android:name="com.app.demo.myApp.GCMIntentService" /> 

Pic my package: enter image description here

+6
source share
3 answers

Problem:

 <service android:name="com.app.demo.myApp.GCMIntentService" /> 

Just give

 <service android:name=".GCMIntentService" /> 

And put the GCMIntentService Java file in the folder indicated by your package name in the manifest.

For example, if you declared com.app.demo.myApp as the name of the application package

Put the GCMIntentService in the same folder structure.

+24
source

I see some potential problems with your manifest, although I'm not sure if they are the cause of your problems:

The following is not required:

 <uses-permission android:name="com.google.android.c2dm.permission.C2D_MESSAGE"/> 

You already have the correct C2D_MESSAGE permission:

  <permission android:name="com.app.demo.myApp.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="com.app.demo.myApp.permission.C2D_MESSAGE" /> 

In addition, GCM is supported from API level 8, so you probably shouldn't specify android:minSdkVersion="7"

+2
source

Make sure you put your GCMIntentService in the main folder. Do not put it in any subfolder and it will work. I had the same problem and it started working.

+2
source

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


All Articles