register notification google gmc gcm fcm app android android-intent google-api google-cloud-messaging google-api-client

notification - SecurityException: no está permitido iniciar el servicio Intent act=com.google.android.c2dm.intent.REGISTER



send push notification to android (2)

Recibo el error SecurityException: Not allowed to start service Intent pero parece que no tiene una buena solución después de buscar en muchos temas.

Por favor, ayúdame,

Gracias,

p / s

Me aseguro de usar el SENDER_ID correcto ya que el número de proyecto se definió en la Google API Console y el package name correcto del package name .

Error

Caused by: java.lang.SecurityException: Not allowed to start service Intent { act=com.google.android.c2dm.intent.REGISTER pkg=com.google.android.gms (has extras) } without permission com.google.android.c2dm.permission.RECEIVE at android.app.ContextImpl.startServiceAsUser(ContextImpl.java:1785) at android.app.ContextImpl.startService(ContextImpl.java:1757) at android.content.ContextWrapper.startService(ContextWrapper.java:480) at com.google.android.gms.gcm.GoogleCloudMessaging.e(Unknown Source) at com.google.android.gms.gcm.GoogleCloudMessaging.register(Unknown Source) at controller.RegisterGCMClientAsync.doInBackground(RegisterGCMClientAsync.java:62) at controller.RegisterGCMClientAsync.doInBackground(RegisterGCMClientAsync.java:18) at android.os.AsyncTask$2.call(AsyncTask.java:287) at java.util.concurrent.FutureTask.run(FutureTask.java:234)             at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)             at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)             at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)             at java.lang.Thread.run(Thread.java:841)

Archivo Manifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="app.cloudstringers" > <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="app.cloudstringers.Cloudstringers" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="ui.fragment.RegisterWithAccountsFragment" /> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> <permission android:name="app.cloudstringers.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <!-- Receiver GCM --> <receiver android:name="app.cloudstringers.GcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="app.cloudstringers" /> </intent-filter> </receiver> <!-- Service GCM --> <service android:exported="true" android:name="app.cloudstringers.GcmIntentService" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <uses-permission android:name="app.cloudstringers.permission.C2D_MESSAGE" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> </application>

SOLUCIÓN Pongo líneas equivocadas. Debería poner la etiqueta <use-permission> fuera de la etiqueta <application> .


Cambie a esto:

<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <uses-permission android:name="app.cloudstringers.permission.C2D_MESSAGE" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <permission android:name="app.cloudstringers.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="app.cloudstringers.Cloudstringers" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="ui.fragment.RegisterWithAccountsFragment" /> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> <!-- Receiver GCM --> <receiver android:name="app.cloudstringers.GcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="app.cloudstringers" /> </intent-filter> </receiver> <!-- Service GCM --> <service android:exported="true" android:name="app.cloudstringers.GcmIntentService" /> </application>

Debe colocar la etiqueta <use-permission> fuera de la etiqueta <application> .


Debe comprobar si Play Store puede funcionar o no. Si no funciona, no puede iniciar el servicio de google.