无法获取主令牌 - java.lang.SecurityException:不允许启动服务Intent

时间:2016-10-11 13:22:12

标签: android google-cloud-messaging

那是什么:

  

无法获得主令牌                                                                                       java.lang.SecurityException:不允许启动服务Intent {   act = com.google.android.c2dm.intent.REGISTER pkg = com.google.android.gms   (有额外的)}未经许可   com.google.android.c2dm.permission.RECEIVE                                                                                           在android.app.ContextImpl.startService(ContextImpl.java:1161)                                                                                           在   android.content.ContextWrapper.startService(ContextWrapper.java:383)                                                                                           在com.google.firebase.iid.zzf.zzb(未知来源)                                                                                           在com.google.firebase.iid.zzf.zza(未知来源)                                                                                           在com.google.firebase.iid.zzf.zzb(未知来源)                                                                                           在com.google.firebase.iid.zzf.zza(未知来源)                                                                                           在com.google.firebase.iid.zzd.zzc(未知来源)                                                                                           在com.google.firebase.iid.zzd.getToken(未知来源)                                                                                           在com.google.firebase.iid.FirebaseInstanceId.getToken(未知来源)                                                                                           在com.google.firebase.iid.FirebaseInstanceId.D(未知来源)                                                                                           在com.google.firebase.iid.FirebaseInstanceIdService.zza(未知   资源)                                                                                           在com.google.firebase.iid.FirebaseInstanceIdService.zzm(未知   资源)                                                                                           在com.google.firebase.iid.zzb $ 2.run(未知来源)                                                                                           在   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)                                                                                           在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:569)                                                                                           在java.lang.Thread.run(Thread.java:856)

我的清单文件:

<uses-permission android:name="android.permission.INTERNET" />

    <!-- [START gcm_permission] -->
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <!-- [END gcm_permission] -->

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity android:name=".Main2Activity">
        </activity>

        <!-- Firebase Notifications -->
        <service
            android:name="com.badboys.gcm.service.MyFirebaseMessagingService"
            android:exported="false" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            </intent-filter>
        </service>
        <service
            android:name="com.badboys.gcm.service.MyFirebaseInstanceIDService"
            android:exported="false">
            <intent-filter>
                <action android:name="com.google.android.gms.iid.InstanceID" />
            </intent-filter>
        </service>

        <!-- ./Firebase Notifications -->
    </application>

2 个答案:

答案 0 :(得分:0)

添加

  

许可           机器人:名字= “permission.C2D_MESSAGE”           android:protectionLevel =“signature”/&gt;

答案 1 :(得分:0)

如果您遗漏了任何内容,请检查Set up a GCM Client for Android

根据我的阅读,您错过了第一个许可,阻止其他应用程序注册/接收您的邮件。

MyFirebaseMessagingService

您还遗漏了一些可能导致此问题的项目。

现在,如果您想要Firebase-specific implementation,请将<action android:name="com.google.firebase.MESSAGING_EVENT"/> 的意图过滤器操作更改为

MyFirebaseInstanceService

<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>

var ii;
var docEvents = jQuery._data(document, "events");
var docClickEvents = docEvents.click;
console.log("docEvents: %O", docEvents);
console.log("docClickEvents: %O", docClickEvents);
console.log("docClickEvents.length: %O", docClickEvents.length);
for (ii = 0; ii < 7; ii += 1) {
    console.log("docClickEvents[%d].namespace=%O", ii, docClickEvents[ii].namespace);
}