Search code examples
androidgoogle-analyticsbroadcastreceivergoogle-cloud-messaging

Permission denial : broadcasting intent android?


I am getting this following error

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

In my app I have google analytic implementation and GCM implementation.

This is receiver declaration

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

This is the 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);
    }
}

}

How can I solve that error?


Solution

  • Use the INSTALL_REFERRER in a separate receiver tag... that would solve your problem.

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