如何测试动态链接或邀请?是否有可以运行的 adb 命令,以及如何生成该链接。
我试过(有不同的变体)
adb shell am start -W -a android.intent.action.VIEW -d "https://play.google.com/store/apps/details?id=com.gonevertical.chatterbox\\&pcampaignid=appinvite_\\&referrer=deep_link_id%3Dhttps://gonevetical.com/chatterbox/invite/group/-KJnkQfRjZfAH9-U_U4a%26invitation_id%3D20832144509-9642991a-de62-4d40-ba93-b991208c2d31" com.gonevertical.chatterbox
项目 https://github.com/branflake2267/chatterbox/blob/master/android/app/src/main/AndroidManifest.xml
最佳答案
在开始测试邀请之前,您应该:
- 将您的应用程序连接到您的 Firebase 项目,从 Firebase console 执行此操作.
- 启用 Firebase 动态链接,从 Firebase console 执行此操作打开“动态链接”部分并在出现提示时接受服务条款。
- Add Firebase to your Android project .
- 将 Firebase Invites 的依赖项添加到您的应用级
build.gradle
文件中:
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
Intent 会打开联系人选择器,用户可以在其中选择要邀请的联系人。邀请通过电子邮件或短信发送。用户选择联系人并发送邀请后,您的应用会收到回调到 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(如果您发送了一个 URL)。要接收应用程序内容的 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
,应用程序会自动重新启动,并使用您的应用程序内容的 URL,您的应用程序可以正常处理这些内容。如果launchDeepLink
参数为false
,您可以手动启动getInvitationIntent返回的intent,在适当的时候处理URL。
这里是关于热点的更多信息Send and Receive Firebase Invites from Your Android App .
Android Studio 中的链接测试
您还可以使用 Android Studio 2.x 版的深度链接测试功能来验证您的应用是否可以使用指定的 URL 启动。要进行设置,首先从 Android Application > General 部分选择Run > Edit Configurations。要测试 HTTP URL,请在启动选项中选择深层链接,然后输入要测试的 URL。如果链接成功,应用程序应在模拟器或连接的设备上启动。否则,运行 窗口中会出现一条错误消息。
Android 调试桥
使用 Android 调试桥测试您的链接是否可以打开您的应用,其中 {URL}
代表在您的应用 list 中声明的 HTTP URL。
adb shell am start -a android.intent.action.VIEW -d "{URL}" com.example.android
在 link有关如何测试您的实现的更多信息。
关于android - 你如何测试 Firebase 邀请?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37802613/