Search code examples
androidandroid-intentbroadcastreceivergoogle-play-services

How to include a bundle extra when testing Android broadcasts?


I'm currently trying to test Google's App Invites, but I'm having a tough time testing the INSTALL_REFERRER broadcast feature without putting an app up on the Play Store

App Invite broadcast intents require a bundle extra named "com.google.android.gms.appinvite.REFERRAL_BUNDLE" and it's checked in AppInviteReferral like so:

public static boolean hasReferral(Intent referralIntent) {
        return referralIntent != null && referralIntent.getBundleExtra("com.google.android.gms.appinvite.REFERRAL_BUNDLE") != null;
}

When testing broadcasts using adb shell am broadcast ..., the best we can do is add extras, but there's not option to add a bundle extra. (documentation here)

Anyone know how a bundle could be included as a part of the broadcast?


Solution

  • In this post say it is impossible to put bundle extra through adb. You can write simple test application and send app invite intent what you want:

    Intent intent = new Intent("com.android.vending.INSTALL_REFERRER");
    intent.setPackage("your_package");
    Bundle bundle = new Bundle();
    bundle.putString("com.android.vending.INSTALL_REFERRER", "your_invite_id");
    bundle.putString("com.google.android.gms.appinvite.DEEP_LINK", "your_deep_link");
    intent.putExtra("com.google.android.gms.appinvite.REFERRAL_BUNDLE", bundle);
    sendBroadcast(intent);
    

    I have tested google app invite in this way, but before tried to sent intent through adb too.