Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you test a firebase invite?

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

like image 708
Brandon Avatar asked Jun 14 '16 03:06

Brandon


2 Answers

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.

like image 66
Gustavo Morales Avatar answered Sep 23 '22 08:09

Gustavo Morales


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.

like image 38
diidu Avatar answered Sep 22 '22 08:09

diidu