你如何测试firebase邀请?

时间:2016-06-14 03:45:08

标签: android firebase firebase-invites

如何测试动态链接或邀请?是否有可以运行的adb命令,以及如何生成该链接。

我尝试过(有不同的变化)

css()

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

4 个答案:

答案 0 :(得分:10)

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

  1. 将您的应用程序连接到Firebase项目,请从Firebase console
  2. 执行此操作
  3. 启用Firebase动态链接,通过打开动态链接部分并在提示时接受服务条款,从Firebase console执行此操作。
  4. Add Firebase to your Android project
  5. 将Firebase邀请的依赖项添加到您的应用级build.gradle文件中:
  6. 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.
                                    // ...
                                }
                            }
                        });
    }
    

    重要提示:以上代码需要已启用AppInvite.API的已连接GoogleApiClient

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

    以下是有关Send and Receive Firebase Invites from Your Android App热门的更多信息。

    Android Studio中的链接测试

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

    Android调试桥

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

    adb shell am start -a android.intent.action.VIEW -d "{URL}" com.example.android
    

    link,有关于如何测试实施的更多信息。

答案 1 :(得分:3)

我通过在FireBase控制台中生成链接,将链接复制到电子邮件,在设备中打开电子邮件并单击设备上的链接来测试它们。您可以通过这种方式验证应用。

如果您想调试链接,请执行相同操作,但将完整链接复制到电子邮件,而不是短链接,并尝试使用完整链接的各种变体。

答案 2 :(得分:1)

我在赏金获奖答案的评论中发现了以下链接。它允许您从邀请中接收邀请并测试处理新安装的代码。

  

要模拟收到朋友的邀请,您可以发送邀请,卸载测试应用,然后点击电子邮件中的链接。

     

这通常会将您发送到Play商店或App Store以下载该应用。因为这是一个测试应用程序,它将链接到不存在的商店页面。

     

点击邀请链接后,在您的设备或模拟器上重新安装并运行该应用,并查看接收方提取的邀请。

答案 3 :(得分:0)

我确实喜欢staackuser2,只提一句。您可以在Google Play封闭式Alpha / Beta上发布您的应用。将自己和另一个电子邮件帐户添加到测试人员列表中。这样,对于注册为测试人员的两台设备,该应用都将在Google Play上显示。 然后,您可以在两个帐户之间发送邀请。单击电子邮件中的链接将转到App Store上的应用程序。如果您安装它,您可以在应用启动时检查邀请ID(以及可能的其他深层链接信息,例如促销代码等)。