如何测试Firebase邀请?

14
如何测试动态链接或邀请?是否有可以运行的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


我尝试使用adb shell来测试安装引荐者,但似乎不起作用。参考命令:am broadcast -a com.android.vending.INSTALL_REFERRER -n {com.your.package}/com.tune.TuneTracker --es referrer "test_referrer=test" - staackuser2
我知道这不是一个有用的评论,更像是一种抱怨:我发现针对Firebase进行测试非常糟糕,完全是个事后补救...但我仍然希望它会随着时间的推移而改善,因为他们做了那些很棒的代码实验室等(我承认真的很棒)。 - Creos
@Creos同意。我有点震惊缺乏文档和示例。我看过Github上的那些,但这个问题是他们说它支持的一个实际用例,但并没有说如何做到这一点的例子。 - staackuser2
这是一个通过ADB命令进行限制测试的应用程序吗? - Gustavo Morales
4个回答

10
在开始邀请测试之前,您需要:
  1. 将您的应用连接到Firebase项目,请从Firebase控制台进行操作。
  2. 启用Firebase动态链接,请从Firebase控制台打开动态链接部分,并在提示时接受服务条款。
  3. 将Firebase添加到您的Android项目中
  4. 在您的应用级build.gradle文件中添加Firebase Invites的依赖项:

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(如果您发送了一个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.
                                // ...
                            }
                        }
                    });
}

重要提示:上面的代码需要连接启用了AppInvite.APIGoogleApiClient

如果launchDeepLink参数为true,则应用程序会自动重新启动,带有指向您的应用程序内容的URL,您的应用程序可以正常处理。如果launchDeepLink参数为false,则可以手动启动由getInvitationIntent返回的意图,在适当时处理URL。

这里有更多关于如何从您的Android应用程序发送和接收Firebase邀请的信息。

在Android Studio中测试链接

您还可以使用Android Studio 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

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


2
你刚才提到的所有信息都只是从 Firebase 邀请设置文档(https://firebase.google.com/docs/invites/android)复制过来的。OP(以及我自己)想知道如何通过邀请链接模拟安装应用程序。目前似乎唯一确定邀请链接是否有效的方法是在将应用程序推送到 Play 商店后进行测试。 - Josh
1
这通常会将您发送到Play Store或App Store以下载应用程序。因为这是一个测试应用程序,它将链接到一个不存在的商店页面。另一种选择是尝试使用Firebase Invites Quickstart。它演示了使用Firebase Invites C++ SDK发送和接收Firebase Invites。当您第一次运行应用程序时,它将检查传入的动态链接或邀请,并报告是否能够获取邀请。还允许您模拟从朋友那里收到邀请。 - Gustavo Morales
它只显示了电子邮件和手机号码邀请选项,我们如何使用所有选项进行邀请,例如WhatsApp、Messenger、Hike等? - Basant

3

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

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


1
我在获奖答案的评论中发现了下面的内容。它可以让您收到邀请并测试处理新安装邀请的代码。
引用: 要模拟从朋友那里收到邀请,您可以发送自己的邀请,卸载测试应用程序,然后单击电子邮件中的链接。 这通常会将您发送到Play Store或App Store下载应用程序。由于这是一个测试应用程序,它将链接到不存在的商店页面。 单击邀请链接后,在设备或模拟器上重新安装和运行应用程序,并查看接收方获取的邀请。

0

我和staackuser2做的一样,但有一个提醒。你可以将应用程序发布到Google Play的封闭Alpha / Beta版本。将自己和另一个电子邮件帐户添加到测试人员列表中。这样,该应用程序将对作为测试人员注册的两个设备可见于Google Play。 然后,您可以在两个帐户之间发送邀请。单击电子邮件中的链接将带您进入应用商店上的应用程序。如果您安装它,可以在应用程序启动时检查邀请ID(以及可能的其他深度链接信息,例如促销代码等)。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接