4

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?

loadedion
  • 2,217
  • 19
  • 41
  • An idea would be to introduce a condition, such that if BuildConfig.DEBUG then augment the `referralIntent` with the `REFERRAL_BUNDLE` extra. – akodiakson Jun 04 '15 at 22:38
  • That wouldn't be very good for testing. I'd like to be able to confirm that the entire broadcast is being received correctly. – loadedion Jun 04 '15 at 23:04
  • Sorry, just not clear what type of test you want and what you are trying to test (i.e., assert). If interacting with the Store seems absolutely essential but impossible, then consider mocking the Store's response as it invokes your receiver. – akodiakson Jun 04 '15 at 23:16
  • Yeah, that's what I'm hoping to do with the broadcasts. For example, you can simulate a Play Store `INSTALL_REFERRER` broadcast event with `adb shell am broadcast -a com.android.vending.INSTALL_REFERRER` -n com.your.package/.path.to.Receiver'. This will send an intent to the Receiver. However, what I'm not sure of is how to attach a `Bundle` extra within that intent. – loadedion Jun 04 '15 at 23:28

1 Answers1

1

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.

Community
  • 1
  • 1
Samik
  • 890
  • 1
  • 8
  • 16
  • Thanks, it looks like that's probably the easiest way to go about it – loadedion Jul 16 '15 at 03:17
  • @Samik how can we create deep link? Any post to follow? – Shajeel Afzal Jul 28 '15 at 13:29
  • @ShajeelAfzal deep link is usual link, for example, http://example.com/profile_id . Link format you can choose what you want. When this link go in your app (through Google Play or something else) you just need retrieve deep link from intent AppInviteReferral.getDeepLink(intent) and parse it, for example, you can extract profile_id from link and open profile activity screen. I cannot found a good post about usage of deeplink. You can download app invite sample from here https://developers.google.com/app-invites/android/guides/start?hl=ru and try it in action. – Samik Jul 28 '15 at 17:47