权限被拒绝:广播意图 android?

Permission denial : broadcasting intent android?

我收到以下错误

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

在我的应用程序中,我有 google 分析实现和 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>

这是接收者class

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);
    }
}

}

我该如何解决该错误?

在单独的接收者标签中使用 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>