GCM no recibe el mensaje de abajo Android 4
Mi aplicación Gcm recibe un mensaje fino de GCM para Android 4 y versiones posteriores. Pero debajo de mi aplicación no se recibe el mensaje.
Este es el GcmBroadcastReceiver:
- Error de servicio de Google Play
- Cómo mover camra a un marcador específico en google maps v2 en android
- Android: ¿Es necesario incluir los servicios de Google Play para usar GCM?
- Firebase Auth no funciona - "Actualizar los servicios de Google Play" msg en el emulador (Android)
- Separar las preocupaciones de la actividad y GoogleApiClient
public class GcmBroadcastReceiver extends WakefulBroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub ComponentName comp = new ComponentName(context.getPackageName(), GCMIntentService.class.getName()); Log.i("GCM BROADCAST", "Begin Broadcast"); startWakefulService(context, intent.setComponent(comp)); setResultCode(Activity.RESULT_OK); } }
Esta es la Intención:
public class GCMIntentService extends IntentService { public static final String TAG = "GcmIntentService"; public static final int NOTIFICATION_ID = 1; public GCMIntentService() { super(Constant.SENDER_ID); } /* (non-Javadoc) * @see android.app.IntentService#onHandleIntent(android.content.Intent) */ @Override protected void onHandleIntent(Intent intent) { // TODO Auto-generated method stub Bundle extras = intent.getExtras(); // Prendo l'istanza di Google Cloud Messaging GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // Prendo la stringa che mi indica il tipo di messaggio String messageType = gcm.getMessageType(intent); Log.i( TAG , "Messaggio ricevuto: " + extras.toString()); if(!extras.isEmpty()) { // Azione nel caso il messaggio sia di errore if(GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) sendNotification("Send error: " + extras.toString()); // Azione nel caso il messaggio sia riguardo l'eliminazione sul server else if(GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) sendNotification("Deleted messages on server: " + extras.toString()); // Azione nel caso sia un messaggio rigardante la nostra applicazione else if(GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { sendNotification(extras.getString("message")); } } GcmBroadcastReceiver.completeWakefulIntent(intent); }
Este es el manifiesto:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.gcmclient" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <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.example.gcm.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.gcmclient.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <receiver android:name="com.example.gcmclient.GcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="com.example.gcmclient.broadcastreceivers" /> </intent-filter> </receiver> <service android:name="com.example.gcmclient.GCMIntentService" /> <service android:name="com.example.gcmclient.RegistrationService"></service> <receiver android:name="com.example.gcmclient.broadcastreceivers.BootHandler" android:enabled="true" android:exported="false"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver> </application>
No puedo entender por qué no funciona debajo de Android 4? Gracias por adelantado.
- ¿Para el acceso a API de Google, puedo crear varios ID de cliente para el mismo nombre de paquete de Android?
- Uso de los nuevos servicios de Google Play
- Cómo agregar biblioteca google play servicio en el estudio android con éxito
- Serializar a una matriz de bytes arrojó una IOException (nunca debería suceder)
- NullPointerException en los servicios de Google Play al llamar a play () en RemotePlaybackClient
- Gradle obtener sabor actual para una tarea específica
- Android Fused Location Api no está usando GPS incluso con PRIORITY_HIGH_ACCURACY?
- ¿Cómo mostrar el diálogo habilitar ubicación como Google Maps?
Cambio
<permission android:name="com.example.gcm.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" />
a
<permission android:name="com.example.gcmclient.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="com.example.gcmclient.permission.C2D_MESSAGE" />
y
<receiver android:name="com.example.gcmclient.GcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="com.example.gcmclient.broadcastreceivers" /> </intent-filter> </receiver>
a
<receiver android:name="com.example.gcmclient.GcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="com.example.gcmclient" /> </intent-filter> </receiver>
- IOS equivalente al servicio de Android?
- Firmar Android APK con un certificado que expira más en el futuro