1

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?

WISHY
  • 11,067
  • 25
  • 105
  • 197

1 Answers1

2

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>
AniV
  • 3,997
  • 1
  • 12
  • 17
  • This is solved my issue. Thnx very much. Can you also how do I get rid of this warning "Exported receiver does not require permission" – WISHY Mar 05 '15 at 05:07
  • It is coming only if target is Lollipop – WISHY Mar 05 '15 at 05:21
  • The warning "Exported receiver does not require permission" means, You have an intent-filter with some action (which means by default you have android:exported="true" set and it can now receive broadcasts from ANY broadcasters outside of your application) Since it can receive broadcasts from ANY broadcasters outside of your application, it warns you by saying "Hey, are you sure ANY broadcaster can invoke you? – AniV Mar 05 '15 at 23:00
  • In my opinion, it is better if you allow only those broadcasters to invoke you that has the permission you have set for this receiver through android:permission" You can remove this warning by adding android:exported="false" to the receiver tag – AniV Mar 05 '15 at 23:00