14

How do you test a dynamic link or invite? Is there an adb command that can be ran, and how would that link be generated.

I've tried (with different variations)

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

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

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Brandon
  • 2,034
  • 20
  • 25
  • I tried using adb shell, the way you would test out an install referrer, but it doesn't seem to work. For reference: `am broadcast -a com.android.vending.INSTALL_REFERRER -n {com.your.package}/com.tune.TuneTracker --es referrer "test_referrer=test"` – staackuser2 Jun 14 '16 at 09:03
  • i know this isn't a helpful comment, more of a rant: i've found testing for firebase to be pretty crappy as in: a total afterthought.... i'm hopeful it'll improve over time though, since they did those fantastic codelabs, etc (which i admit was really great) – Creos Jun 20 '16 at 03:07
  • @Creos agreed. i was a bit shocked at the lack of documentation and examples. I have seen the ones on Github, but this question is an example of an actual use case they say it supports, but does not actually say how to do it. – staackuser2 Jun 21 '16 at 07:08
  • Is a restriction test application from an ADB command? – Gustavo Morales Jun 21 '16 at 18:44

4 Answers4

10

Before start testing invites you should:

  1. Connect your app to your Firebase project, do so from the Firebase console.
  2. Enable Firebase Dynamic Links, do so from the Firebase console by opening the Dynamic Links section and accepting the terms of service if prompted.
  3. Add Firebase to your Android project.
  4. Add the dependency for Firebase Invites to your app-level build.gradle file:

Gradle file:

compile 'com.google.firebase:firebase-invites:9.0.2'

Send Invitations

Build an Intent using the AppInviteInvitation.IntentBuilder class:

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);
}

Launching the AppInviteInvitation intent opens the contact chooser where the user selects the contacts to invite. Invites are sent via email or SMS. After the user chooses contacts and sends the invite, your app receives a callback to 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
            // ...
        }
    }
}

Receive invitations

When a user receives an invitation, if the user has not yet installed the app, they can choose to install the app from the Google Play Store. Then, after the app is installed, or if the app was already installed, the app starts and receives the URL to its content, if you sent one. To receive the URL to your app's content, call the getInvitation method:

@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.
                                // ...
                            }
                        }
                    });
}

IMPORTANT: Code above requires a connected GoogleApiClient with AppInvite.API enabled.

If the launchDeepLink parameter is true, the app automatically relaunches with the URL to your app's content, which your app can handle normally. If the launchDeepLink parameter is false, you can manually start the intent returned by getInvitationIntent to handle the URL when appropriate.

Here is more info about hot to Send and Receive Firebase Invites from Your Android App.

Link Testing in Android Studio

Also you can Use the Deep Link Testing feature for Android Studio version 2.x feature to verify that your app can be launched with a specified URL. To set this up, first select Run > Edit Configurations from the Android Application > General section. To test a HTTP URL, select Deep link in the Launch Options, and then input the URL to test. If the link is successful, the app should launch in the emulator or on the connected device. Otherwise, an error message appears in the Run window.

Android Debug Bridge

Test that your links open your app by using the Android Debug Bridge, where {URL} represents the HTTP URL declared in your app manifest.

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

At link there is more info about how to test your implementation.

Gustavo Morales
  • 2,614
  • 9
  • 29
  • 37
  • 2
    All the info you just mentioned is just copied from the setup docs for Firebase invites (https://firebase.google.com/docs/invites/android). OP (and myself) want to know how you can simulate installing the app via an invite link. Right now it seems like the only way to be sure invite links work is to test after pushing your app to the play store. – Josh Jun 22 '16 at 20:16
  • 1
    This would normally send you to the Play Store or App Store to download the app. Because this is a test app, it will link to a nonexistent store page. Another alternative is try to use [Firebase Invites Quickstart](https://github.com/firebase/quickstart-cpp/blob/master/invites/testapp/readme.md). It demonstrates both sending and receiving Firebase Invites using the Firebase Invites C++ SDK. When you first run the app, it will check for an incoming dynamic link or invitation, and report whether it was able to fetch an invite. Also allow you to simulate receiving an invitation from a friend. – Gustavo Morales Jun 22 '16 at 20:32
  • its showing only email and mobile number option to invite, how can we invite using all option, like whatsapp, messenger, hike etc? – Basant Aug 21 '19 at 11:04
3

I tested them by generating the links in FireBase console, copying the link(s) to an email, opening the email in a device and clicking the links on the device. You can verify the app that way.

If you want to debug the links, do the same, but copy the full link to an email, not the short one and experiment with variations of the full link.

diidu
  • 2,823
  • 17
  • 32
1

I found the below in a link posted in the comment of the bounty winning answer. It allows you to receive an invitation and test your code of handling a new install from an invitation.

To simulate receiving an invitation from a friend, you can send yourself an invite, uninstall the test app, then click the link in your e-mail.

This would normally send you to the Play Store or App Store to download the app. Because this is a test app, it will link to a nonexistent store page.

After clicking the invite link, re-install and run the app on your device or emulator, and see the invitation fetched on the receiving side.

Community
  • 1
  • 1
staackuser2
  • 12,172
  • 4
  • 42
  • 40
0

I did just like staackuser2, with one mention. You can publish your app on Google Play closed Alpha / Beta. Add yourself and another email account to the testers list. That way, the app will be visible on Google Play for both devices registered as testers. You can then send invites betweeen the two accounts. Clicking on the link in the email will take you to the app on the App Store. If you install it, you can check for the invitation id (and possible other deeplink information, such as promo code etc.) at app startup.