How to include a bundle extra when testing Android broadcasts?

对着背影说爱祢 提交于 2019-12-10 06:56:03

问题


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?


回答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.



来源:https://stackoverflow.com/questions/30655231/how-to-include-a-bundle-extra-when-testing-android-broadcasts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!