你如何测试firebase邀请?

Bra*_*don 14 android firebase firebase-invites

您如何测试动态链接或邀请?是否有可以运行的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
Run Code Online (Sandbox Code Playgroud)

项目 https://github.com/branflake2267/chatterbox/blob/master/android/app/src/main/AndroidManifest.xml

Mor*_*ski 10

在开始测试邀请之前,您应该:

  1. 将您的应用程序连接到Firebase项目,从Firebase控制台执行此操作.
  2. 启用Firebase动态链接,通过打开动态链接部分并在提示时接受服务条款,从Firebase控制台执行此操作.
  3. 将Firebase添加到您的Android项目中.
  4. 将Firebase邀请的依赖项添加到您的应用级build.gradle文件:

Gradle文件:

compile 'com.google.firebase:firebase-invites:9.0.2'
Run Code Online (Sandbox Code Playgroud)

发送邀请

Intent使用AppInviteInvitation.IntentBuilder类构建一个:

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);
}
Run Code Online (Sandbox Code Playgroud)

启动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
            // ...
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

收到邀请

当用户收到邀请时,如果用户尚未安装该应用,则他们可以选择从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.
                                // ...
                            }
                        }
                    });
}
Run Code Online (Sandbox Code Playgroud)

重要提示:上面的代码需要连接GoogleApiClientAppInvite.API启用.

如果launchDeepLink参数为true,则应用会自动重新启动应用内容的网址,您的应用可以正常处理该内容.如果launchDeepLink参数是false,则可以手动启动getInvitationIntent返回的意图以在适当时处理URL.

以下是有关从Android应用发送和接收Firebase邀请的热门信息.

Android Studio中的链接测试

您还可以使用Android Studio版本2.x功能的深层链接测试功能来验证您的应用是否可以使用指定的URL启动.要进行此设置,请首先从Android应用程序>常规部分选择运行>编辑配置.要测试HTTP URL,请在" 启动选项"中选择" 深层链接 " ,然后输入要测试的URL.如果链接成功,应用程序应在模拟器或连接的设备上启动.否则," 运行"窗口中将显示一条错误消息.

Android调试桥

使用Android调试桥测试您的链接是否打开了您的应用,其中Android调试桥{URL}表示应用清单中声明的​​HTTP URL.

adb shell am start -a android.intent.action.VIEW -d "{URL}" com.example.android
Run Code Online (Sandbox Code Playgroud)

链接中有更多关于如何测试您的实现的信息.

  • 您刚才提到的所有信息都是从 Firebase 邀请的设置文档 (https://firebase.google.com/docs/invites/android) 中复制的。OP(和我自己)想知道如何通过邀请链接模拟安装应用程序。现在似乎确保邀请链接有效的唯一方法是在将您的应用程序推送到 Play 商店后进行测试。 (2认同)