SecurityException异常:不允许启动服务意向{行动= com.google.android.c2dm.intent.REGISTER PKG = com.google.android.gms(有临时演员)} [英] SecurityException: Not allowed to start service Intent { act=com.google.android.c2dm.intent.REGISTER pkg=com.google.android.gms (has extras) }

查看:1597
本文介绍了SecurityException异常:不允许启动服务意向{行动= com.google.android.c2dm.intent.REGISTER PKG = com.google.android.gms(有临时演员)}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让谷歌从我的GCM registrationId。

我的code:

 字符串SENDER_ID =722 ****** 53;/ **
 *与注册服务器GCM异步应用程序。
 *所述p为H.;
 *商店的注册ID,并在应用程序的应用程序版本code
 *共享preferences。
 * /
私人无效registerInBackground(){
    新的AsyncTask<太虚,太虚,字符串>(){
        @覆盖
        保护字符串doInBackground(虚空...... PARAMS){
            弦乐味精=;
            尝试{
                如果(GCM == NULL){
                    GCM = GoogleCloudMessaging.getInstance(上下文);
                }
                REGID = gcm.register(SENDER_ID);
                味精=设备注册,注册ID =+ REGID;                //你应该送过来的注册ID为您的服务器
                // HTTP,因此它
                //可以使用GCM / HTTP或CCS将消息发送到您的应用程序。
                sendRegistrationIdToBackend();                //对于这个演示:我们并不需要发送它,因为
                //设备将发送
                //上游邮件服务器的回显信息
                // 使用
                从'邮件中的地址//。                //坚持的REGID - 无需再次注册。
                storeRegistrationId(背景下,REGID);
            }赶上(IOException异常前){
                味精=错误:+ ex.getMessage();
                //如果有错误,不要只是不断地尝试注册。
                //要求用户再次点击一个按钮,或执行
                //指数回退。
            }
            返回味精;
        }        @覆盖
        保护无效onPostExecute(弦乐味精){
            mDisplay.append(MSG +\\ n);
        }
    } .execute(NULL,NULL,NULL);
}

我得到一个错误:

  03-01 19:15:36.261:E / AndroidRuntime(3467):致命异常:AsyncTask的#1
03-01 19:15:36.261:E / AndroidRuntime(3467):了java.lang.RuntimeException:执行doInBackground发生错误()
03-01 19:15:36.261:E / AndroidRuntime(3467):在android.os.AsyncTask $ 3.done(AsyncTask.java:299)
03-01 19:15:36.261:E / AndroidRuntime(3467):在java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
03-01 19:15:36.261:E / AndroidRuntime(3467):在java.util.concurrent.FutureTask.setException(FutureTask.java:219)
03-01 19:15:36.261:E / AndroidRuntime(3467):在java.util.concurrent.FutureTask.run(FutureTask.java:239)
03-01 19:15:36.261:E / AndroidRuntime(3467):在android.os.AsyncTask $ SerialExecutor $ 1.run(AsyncTask.java:230)
03-01 19:15:36.261:E / AndroidRuntime(3467):在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
03-01 19:15:36.261:E / AndroidRuntime(3467):在java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:573)
03-01 19:15:36.261:E / AndroidRuntime(3467):在java.lang.Thread.run(Thread.java:841)
03-01 19:15:36.261:E / AndroidRuntime(3467):java.lang.SecurityException异常:产生的原因不允许启动服务意向{行动= com.google.android.c2dm.intent.REGISTER PKG = com.google .android.gms(有临时演员)}擅自com.google.android.c2dm.permission.RECEIVE
03-01 19:15:36.261:E / AndroidRuntime(3467):在android.app.ContextImpl.startServiceAsUser(ContextImpl.java:1800)
03-01 19:15:36.261:E / AndroidRuntime(3467):在android.app.ContextImpl.startService(ContextImpl.java:1772)
03-01 19:15:36.261:E / AndroidRuntime(3467):在android.content.ContextWrapper.startService(ContextWrapper.java:480)
03-01 19:15:36.261:E / AndroidRuntime(3467):在com.google.android.gms.gcm.GoogleCloudMessaging.b(来源不明)
03-01 19:15:36.261:E / AndroidRuntime(3467):在com.google.android.gms.gcm.GoogleCloudMessaging.register(来源不明)
03-01 19:15:36.261:E / AndroidRuntime(3467):在com.example.gcm.DemoActivity $ 1.doInBackground(DemoActivity.java:177)
03-01 19:15:36.261:E / AndroidRuntime(3467):在com.example.gcm.DemoActivity $ 1.doInBackground(DemoActivity.java:1)
03-01 19:15:36.261:E / AndroidRuntime(3467):在android.os.AsyncTask $ 2.call(AsyncTask.java:287)
03-01 19:15:36.261:E / AndroidRuntime(3467):在java.util.concurrent.FutureTask.run(FutureTask.java:234)
03-01 19:15:36.261:E / AndroidRuntime(3467):... 4个

这是我的清单:

 <?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=com.example.manyexampleapp
    安卓的installLocation =preferExternal
    安卓版code =1
    机器人:=的versionName1.0>    <用途-SDK
        安卓的minSdkVersion =11
        机器人:targetSdkVersion =18/>    <使用许可权的android:NAME =android.permission.INTERNET对/>
    <使用许可权的android:NAME =android.permission.ACCESS_NETWORK_STATE/>
    <使用许可权的android:NAME =android.permission.RECEIVE_BOOT_COMPLETED/>
    <使用许可权的android:NAME =android.permission.ACCESS_FINE_LOCATION/>
    <使用许可权的android:NAME =android.permission.GET_ACCOUNTS/>
    <使用许可权的android:NAME =android.permission.WAKE_LOCK/>
    <使用许可权的android:NAME =com.example.manyexampleapp.c2dm.permission.RECEIVE/>
    <使用许可权的android:NAME =com.example.manyexampleapp.gcm.permission.C2D_MESSAGE/>    <许可
        机器人:名字=com.example.manyexampleapp.gcm.permission.C2D_MESSAGE
        安卓的ProtectionLevel =签名/>    <应用
        机器人:名字=com.zoomer.ifs.BaseApplication
        机器人:allowBackup =真
        机器人:图标=@绘制/ ic_launcher
        机器人:标签=@字符串/ APP_NAME
        机器人:主题=@风格/ AppTheme>
        &所述;元数据
            机器人:名字=com.google.android.gms.version
            机器人:值=@整数/ GOOGLE_PLAY_SERVICES_VERSION/>
         <活动
            机器人:名字=com.zoomer.ifs.MainActivity
            机器人:标签=@字符串/ APP_NAME
            机器人:configChanges =方向| keyboardHidden |屏幕尺寸
                机器人:launchMode =singleTop>
&所述;! - &下;意图滤光器>
                <作用机器人:名字=android.intent.action.MAIN/>
                <类机器人:名字=android.intent.category.LAUNCHER/>
            &所述; /意图滤光器> - >
        < /活性GT;     &所述;! - PUSH - >        <! -
          WakefulBroadcastReceiver将从GCM收到意图
          服务,并将它们交给定制IntentService。          该com.google.android.c2dm.permission.SEND需要许可
          所以只有GCM服务,可以为应用程序发送数据消息。
         - >
        <接收
            机器人:名字=com.example.gcm.GcmBroadcastReceiver
            机器人:权限=com.google.android.c2dm.permission.SEND>
            &所述;意图滤光器>
                <! - 收到实际的消息。 - >
                <作用机器人:名字=com.google.android.c2dm.intent.RECEIVE/>
                <类机器人:名字=com.example.manyexampleapp/>
            &所述; /意图滤光器>
        < /接收器>
        <服务机器人:名字=com.example.gcm.GcmIntentService/>         <活动
            机器人:名字=com.example.gcm.DemoActivity>
            &所述;意图滤光器>
                <作用机器人:名字=android.intent.action.MAIN/>
                <类机器人:名字=android.intent.category.LAUNCHER/>
            &所述; /意图滤光器>
        < /活性GT;           <! - DB - >
        <活动
            机器人:名字=com.example.db.DbActivity
            机器人:标签=@字符串/ APP_NAME>
            &所述;意图滤光器>
            &所述; /意图滤光器>
        < /活性GT;
        <活动
            机器人:名字=com.example.http.RestGetActivity
            机器人:标签=@字符串/ APP_NAME
            机器人:主题=@安卓风格/ Theme.Black.NoTitleBar.Fullscreen>
        < /活性GT;
        <活动
            机器人:名字=com.example.fb.FacebookLoginActivity
            机器人:标签=@字符串/ APP_NAME>            <! -
                      &所述;意图滤光器>
                                <作用机器人:名字=android.intent.action.MAIN/>
                <类机器人:名字=android.intent.category.LAUNCHER/>
            &所述; /意图滤光器>
             - >
        < /活性GT;
        <活动
            机器人:名字=com.example.http.SendFeedbackActivity
            机器人:标签=@字符串/ APP_NAME>            <! -
                 &所述;意图滤光器>
                <作用机器人:名字=android.intent.action.MAIN/>                <类机器人:名字=android.intent.category.LAUNCHER/>
            &所述; /意图滤光器>
             - >
        < /活性GT;
        <活动
            机器人:名字=com.zoomer.general.SearchNearbyOffersActivity
            机器人:标签=@字符串/ APP_NAME>
            &所述;意图滤光器>
            &所述; /意图滤光器>
        < /活性GT;
        <活动
            机器人:名字=com.facebook.LoginActivity
            机器人:标签=@字符串/ APP_NAME>
            &所述;意图滤光器>
            &所述; /意图滤光器>
        < /活性GT;
        <活动机器人:名字=com.example.manyexampleapp.StoresListActivity>
            &所述;意图滤光器>
            &所述; /意图滤光器>
        < /活性GT;
        <活动机器人:名字=com.example.fb.ShareActivity>
            &所述;意图滤光器>
            &所述; /意图滤光器>
        < /活性GT;
        <活动机器人:名字=com.example.notifications.NotificationsActivity>
            &所述;意图滤光器>
            &所述; /意图滤光器>
        < /活性GT;
        <活动机器人:名字=com.example.fb2.no_use.MainActivity>
            &所述;意图滤光器>
            &所述; /意图滤光器>
        < /活性GT;
        <活动机器人:名字=com.zoomer.offers.OffersListActivity>            <! -
                 &所述;意图滤光器>
                <作用机器人:名字=android.intent.action.MAIN/>
                <类机器人:名字=android.intent.category.LAUNCHER/>
            &所述; /意图滤光器>
             - >
        < /活性GT;
        <活动机器人:名字=com.example.http.SearchNearbyOffersActivity>
&所述;! - &下;意图滤光器>
                <作用机器人:名字=android.intent.action.MAIN/>
                <类机器人:名字=android.intent.category.LAUNCHER/>
            &所述; /意图滤光器> - >
        < /活性GT;        <服务
            机器人:名字=com.example.geo.LocationService
            机器人:启用=真/>        <接收机器人:名字=com.example.manyexampleapp.BootReceiver>
            &所述;意图滤光器>
                <作用机器人:名字=android.intent.action.BOOT_COMPLETED/>
                <作用机器人:名字=com.example.manyexampleapp.LocationService.LOCATION_BROAD_MSG/>
            &所述; /意图滤光器>
        < /接收器>        &所述;元数据
            机器人:名字=com.facebook.sdk.ApplicationId
            机器人:值=@字符串/ APP_ID/>
    < /用途>< /清单>


解决方案

修改

 <使用许可权的android:NAME =com.example.manyexampleapp.c2dm.permission.RECEIVE/>

 <! - 这个程序有权限注册和接收数据信息。 - >
    <使用许可权的android:NAME =com.google.android.c2dm.permission.RECEIVE/>

您所得到的异常,因为你还没有定义所需的权限

I try to get my GCM registrationId from Google.

my code:

String SENDER_ID = "722******53";

/**
 * Registers the application with GCM servers asynchronously.
 * <p>
 * Stores the registration ID and the app versionCode in the application's
 * shared preferences.
 */
private void registerInBackground() {
    new AsyncTask<Void, Void, String>() {
        @Override
        protected String doInBackground(Void... params) {
            String msg = "";
            try {
                if (gcm == null) {
                    gcm = GoogleCloudMessaging.getInstance(context);
                }
                regid = gcm.register(SENDER_ID);
                msg = "Device registered, registration ID=" + regid;

                // You should send the registration ID to your server over
                // HTTP, so it
                // can use GCM/HTTP or CCS to send messages to your app.
                sendRegistrationIdToBackend();

                // For this demo: we don't need to send it because the
                // device will send
                // upstream messages to a server that echo back the message
                // using the
                // 'from' address in the message.

                // Persist the regID - no need to register again.
                storeRegistrationId(context, regid);
            } catch (IOException ex) {
                msg = "Error :" + ex.getMessage();
                // If there is an error, don't just keep trying to register.
                // Require the user to click a button again, or perform
                // exponential back-off.
            }
            return msg;
        }

        @Override
        protected void onPostExecute(String msg) {
            mDisplay.append(msg + "\n");
        }
    }.execute(null, null, null);
}

I get an error:

03-01 19:15:36.261: E/AndroidRuntime(3467): FATAL EXCEPTION: AsyncTask #1
03-01 19:15:36.261: E/AndroidRuntime(3467): java.lang.RuntimeException: An error occured while executing doInBackground()
03-01 19:15:36.261: E/AndroidRuntime(3467):     at android.os.AsyncTask$3.done(AsyncTask.java:299)
03-01 19:15:36.261: E/AndroidRuntime(3467):     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
03-01 19:15:36.261: E/AndroidRuntime(3467):     at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
03-01 19:15:36.261: E/AndroidRuntime(3467):     at java.util.concurrent.FutureTask.run(FutureTask.java:239)
03-01 19:15:36.261: E/AndroidRuntime(3467):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
03-01 19:15:36.261: E/AndroidRuntime(3467):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
03-01 19:15:36.261: E/AndroidRuntime(3467):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
03-01 19:15:36.261: E/AndroidRuntime(3467):     at java.lang.Thread.run(Thread.java:841)
03-01 19:15:36.261: E/AndroidRuntime(3467): 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
03-01 19:15:36.261: E/AndroidRuntime(3467):     at android.app.ContextImpl.startServiceAsUser(ContextImpl.java:1800)
03-01 19:15:36.261: E/AndroidRuntime(3467):     at android.app.ContextImpl.startService(ContextImpl.java:1772)
03-01 19:15:36.261: E/AndroidRuntime(3467):     at android.content.ContextWrapper.startService(ContextWrapper.java:480)
03-01 19:15:36.261: E/AndroidRuntime(3467):     at com.google.android.gms.gcm.GoogleCloudMessaging.b(Unknown Source)
03-01 19:15:36.261: E/AndroidRuntime(3467):     at com.google.android.gms.gcm.GoogleCloudMessaging.register(Unknown Source)
03-01 19:15:36.261: E/AndroidRuntime(3467):     at com.example.gcm.DemoActivity$1.doInBackground(DemoActivity.java:177)
03-01 19:15:36.261: E/AndroidRuntime(3467):     at com.example.gcm.DemoActivity$1.doInBackground(DemoActivity.java:1)
03-01 19:15:36.261: E/AndroidRuntime(3467):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
03-01 19:15:36.261: E/AndroidRuntime(3467):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
03-01 19:15:36.261: E/AndroidRuntime(3467):     ... 4 more

here is my manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.manyexampleapp"
    android:installLocation="preferExternal"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="18" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="com.example.manyexampleapp.c2dm.permission.RECEIVE" />
    <uses-permission android:name="com.example.manyexampleapp.gcm.permission.C2D_MESSAGE" />

    <permission
        android:name="com.example.manyexampleapp.gcm.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

    <application
        android:name="com.zoomer.ifs.BaseApplication"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />


         <activity
            android:name="com.zoomer.ifs.MainActivity"
            android:label="@string/app_name"
            android:configChanges="orientation|keyboardHidden|screenSize"
                android:launchMode="singleTop">
<!--             <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter> -->
        </activity>

     <!--     PUSH -->

        <!--
          WakefulBroadcastReceiver that will receive intents from GCM
          services and hand them to the custom IntentService.

          The com.google.android.c2dm.permission.SEND permission is necessary
          so only GCM services can send data messages for the app.
        -->
        <receiver
            android:name="com.example.gcm.GcmBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <!-- Receives the actual messages. -->
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <category android:name="com.example.manyexampleapp" />
            </intent-filter>
        </receiver>
        <service android:name="com.example.gcm.GcmIntentService" />

         <activity
            android:name="com.example.gcm.DemoActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

           <!--     DB -->
        <activity
            android:name="com.example.db.DbActivity"
            android:label="@string/app_name" >
            <intent-filter>
            </intent-filter>
        </activity>
        <activity
            android:name="com.example.http.RestGetActivity"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
        </activity>
        <activity
            android:name="com.example.fb.FacebookLoginActivity"
            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="com.example.http.SendFeedbackActivity"
            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="com.zoomer.general.SearchNearbyOffersActivity"
            android:label="@string/app_name" >
            <intent-filter>
            </intent-filter>
        </activity>
        <activity
            android:name="com.facebook.LoginActivity"
            android:label="@string/app_name" >
            <intent-filter>
            </intent-filter>
        </activity>
        <activity android:name="com.example.manyexampleapp.StoresListActivity" >
            <intent-filter>
            </intent-filter>
        </activity>
        <activity android:name="com.example.fb.ShareActivity" >
            <intent-filter>
            </intent-filter>
        </activity>
        <activity android:name="com.example.notifications.NotificationsActivity" >
            <intent-filter>
            </intent-filter>
        </activity>
        <activity android:name="com.example.fb2.no_use.MainActivity" >
            <intent-filter>
            </intent-filter>
        </activity>
        <activity android:name="com.zoomer.offers.OffersListActivity" >

            <!--
                 <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            -->
        </activity>
        <activity android:name="com.example.http.SearchNearbyOffersActivity" >
<!--             <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter> -->
        </activity>

        <service
            android:name="com.example.geo.LocationService"
            android:enabled="true" />

        <receiver android:name="com.example.manyexampleapp.BootReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="com.example.manyexampleapp.LocationService.LOCATION_BROAD_MSG" />
            </intent-filter>
        </receiver>

        <meta-data
            android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/app_id" />
    </application>

</manifest>

解决方案

Change

<uses-permission android:name="com.example.manyexampleapp.c2dm.permission.RECEIVE" />

to

 <!-- This app has permission to register and receive data message. -->
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

You are getting the exception because you have not defined the required permissions

这篇关于SecurityException异常:不允许启动服务意向{行动= com.google.android.c2dm.intent.REGISTER PKG = com.google.android.gms(有临时演员)}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆