开始测试之前邀请您应该:
- 您的应用程序连接到您的Firebase项目,请从开始3210。
- 启用Firebase动态链接,从Firebase console开启动态链接部分并接受服务条款(如果提示),请执行此操作。
- Add Firebase to your Android project。
- 添加依赖于火力地堡邀请到您的应用程序级
build.gradle
文件:
摇篮文件:
compile 'com.google.firebase:firebase-invites:9.0.2'
发送邀请
使用AppInviteInvitation.IntentBuilder类建立一个Intent
:
private void onInviteClicked() {
Intent intent = new AppInviteInvitation.IntentBuilder(getString(R.string.invitation_title))
.setMessage(getString(R.string.invitation_message))
.setDeepLink(Uri.parse(getString(R.string.invitation_deep_link)))
.setCustomImage(Uri.parse(getString(R.string.invitation_custom_image)))
.setCallToActionText(getString(R.string.invitation_cta))
.build();
startActivityForResult(intent, REQUEST_INVITE);
}
启动AppInviteInvitation
意图打开用户选择要邀请的联系人的联系选择器。邀请通过电子邮件或短信发送。用户选择联系人和发送之后的邀请,您的应用程序将收到回调到onActivityResult
:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(TAG, "onActivityResult: requestCode=" + requestCode + ", resultCode=" + resultCode);
if (requestCode == REQUEST_INVITE) {
if (resultCode == RESULT_OK) {
// Get the invitation IDs of all sent messages
String[] ids = AppInviteInvitation.getInvitationIds(resultCode, data);
for (String id : ids) {
Log.d(TAG, "onActivityResult: sent invitation " + id);
}
} else {
// Sending failed or it was canceled, show failure message to the user
// ...
}
}
}
接收邀请
当用户收到邀请时,如果用户没有安装应用程序,他们可以选择从Google Play商店安装应用。然后,在安装应用程序之后,或者如果应用程序已安装,则应用程序将启动并接收其内容的URL(如果已发送)。要接收您的应用网址的内容,调用getInvitation
方法:
@Override
protected void onCreate(Bundle savedInstanceState) {
// ...
// Create an auto-managed GoogleApiClient with access to App Invites.
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(AppInvite.API)
.enableAutoManage(this, this)
.build();
// Check for App Invite invitations and launch deep-link activity if possible.
// Requires that an Activity is registered in AndroidManifest.xml to handle
// deep-link URLs.
boolean autoLaunchDeepLink = true;
AppInvite.AppInviteApi.getInvitation(mGoogleApiClient, this, autoLaunchDeepLink)
.setResultCallback(
new ResultCallback<AppInviteInvitationResult>() {
@Override
public void onResult(AppInviteInvitationResult result) {
Log.d(TAG, "getInvitation:onResult:" + result.getStatus());
if (result.getStatus().isSuccess()) {
// Extract information from the intent
Intent intent = result.getInvitationIntent();
String deepLink = AppInviteReferral.getDeepLink(intent);
String invitationId = AppInviteReferral.getInvitationId(intent);
// Because autoLaunchDeepLink = true we don't have to do anything
// here, but we could set that to false and manually choose
// an Activity to launch to handle the deep link here.
// ...
}
}
});
}
重要提示:上述代码需要连接GoogleApiClient启用AppInvite.API
。
如果launchDeepLink
参数是true
,该应用程序会自动与您的应用网址的内容,您的应用可以正常处理重新登场。如果launchDeepLink
参数是false
,则可以手动启动由getInvitationIntent返回的意图以在适当时处理URL。
这是关于热到Send and Receive Firebase Invites from Your Android App的更多信息。
链路测试Android Studio中
您还可以使用Android的工作室版本2.x功能的深层链接测试功能来验证您的应用程序可以与指定的URL启动。要进行设置,首先选择运行>编辑配置从Android应用程序>常规部分。要测试HTTP URL,请在启动选项中选择深层链接,然后输入要测试的URL。如果链接成功,应用程序应该在模拟器或连接的设备上启动。否则,在运行窗口中出现错误消息。
的Android调试桥
测试您的链接中使用Android调试桥,其中{URL}
代表在应用清单中声明的HTTP URL打开您的应用。
adb shell am start -a android.intent.action.VIEW -d "{URL}" com.example.android
在link有关于如何测试您的实施的更多信息。
我尝试过使用adb shell,您将测试安装引用程序的方式,但似乎不起作用。作为参考:'广播-a com.android.vending.INSTALL_REFERRER -n {com.your.package} /com.tune.TuneTracker - 引用者“test_referrer = test”' – staackuser2
我知道这不是一个有用的评论,更多的咆哮:我已经发现测试firebase是相当糟糕的,因为:总是事后......我希望它会随着时间的推移而改善,因为他们做了那些奇妙的代码段等(我承认这真的很棒) – Creos
@Creos同意了。我对缺乏文档和例子感到有些震惊。我已经看到了Github上的那些,但这个问题是他们说它支持的实际用例的一个例子,但实际上并没有说明如何去做。 – staackuser2