SecurityException: 不允许启动服务 Intent act=com.google.android.c2dm.intent.REGISTER

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25399845/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 09:25:01  来源:igfitidea点击:

SecurityException: Not allowed to start service Intent act=com.google.android.c2dm.intent.REGISTER

androidandroid-intentgoogle-apigoogle-cloud-messaginggoogle-api-client

提问by Huy Tower

I get the error SecurityException: Not allowed to start service Intentbut looks like it do not have good solution after searching many topics.

我收到错误,SecurityException: Not allowed to start service Intent但在搜索许多主题后似乎没有好的解决方案。

Please help me,

请帮我,

Thanks,

谢谢,

p/s :

p/s :

I'm make sure I used correct SENDER_IDas project number was defined at Google API Consoleand correct package name.

我确保我使用的是正确的,SENDER_ID因为项目编号定义在Google API Console和正确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.call(AsyncTask.java:287)
            at java.util.concurrent.FutureTask.run(FutureTask.java:234)
????????????at android.os.AsyncTask$SerialExecutor.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)

Manifest.xml file:

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>

SOLUTIONI put wrong lines. Should put <use-permission>tag outside of <application>tag.

解决方案我放错了行。应该将<use-permission>标签放在标签之外<application>

采纳答案by Kishan Dhamat

Change to this:

改成这样:

    <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>

You should put <use-permission>tag outside of <application>tag.

你应该把<use-permission>标签放在标签之外<application>

回答by Cu'i Bap

You should check if play store can work or not. If it does not work, it can not start google service.

您应该检查 Play 商店是否可以工作。如果它不起作用,则无法启动谷歌服务。