权限拒绝:广播意图android?

时间:2015-03-04 10:24:30

标签: android google-analytics broadcastreceiver google-cloud-messaging

我收到以下错误

Permission Denial: broadcasting Intent { act=com.android.vending.INSTALL_REFERRER flg=0x10 cmp=com.app/.MyBroadcastReceiver (has extras) } from null (pid=1853, uid=2000) requires com.google.android.c2dm.permission.SEND due to receiver com.app/.MyBroadcastReceiver

在我的应用中,我有谷歌分析实施和GCM实施。

这是接收者声明

 <receiver
        android:name="com.app.MyBroadcastReceiver"
        android:exported="true"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>

            <!-- Receives the actual messages. -->
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <!-- Receives the registration id. -->
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <action android:name="com.android.vending.INSTALL_REFERRER" />

            <category android:name="com.app" />
        </intent-filter>
    </receiver>

这是接收器类

public class MyBroadcastReceiver extends WakefulBroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {

    Logger.d("intent action: " + intent.getAction());


    if("com.android.vending.INSTALL_REFERRER".equalsIgnoreCase(intent.getAction())){

        String r = intent.getExtras().getString("referrer");
        Logger.d("referrer: " + r);



    }else{

        ComponentName comp = new ComponentName(context.getPackageName(),
            AppprixGCMIntentService.class.getName());
        startWakefulService(context, (intent.setComponent(comp)));
        setResultCode(Activity.RESULT_OK);
    }
}

}

如何解决该错误?

1 个答案:

答案 0 :(得分:2)

在单独的接收器标签中使用INSTALL_REFERRER ......可以解决您的问题。

<application

android:hardwareAccelerated="true"
android:icon="@mitmap/ic_launcher"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/AppTheme" >
<receiver
    android:name=".xyz"
    android:exported="true" >
    <intent-filter>
        <action android:name="com.android.vending.INSTALL_REFERRER" />
    </intent-filter>
</receiver>