quickstart-android icon indicating copy to clipboard operation
quickstart-android copied to clipboard

Firebase Dynamic links always returned CANCELED

Open CeccoCQ opened this issue 10 years ago • 49 comments

I'm using dynamic links for my app.

I've followed the tutorial step-by-step and I'm able to open the app by clicking on the link posted on facebook.

But when I invoke getInvitation, I always have CANCELED as status of AppInviteInvitationResult.

    AppInvite.AppInviteApi.getInvitation(mGoogleApiClient, this, false).setResultCallback(
            new ResultCallback<AppInviteInvitationResult>() {
                @Override
                public void onResult(@NonNull AppInviteInvitationResult result) {
                    if (result.getStatus().isSuccess()) {
                        // Extract deep link from Intent
                        Intent intent = result.getInvitationIntent();
                        String deepLink = AppInviteReferral.getDeepLink(intent);

                        // [END_EXCLUDE]
                    } else {
                        Log.d("StartActivity", "getInvitation: no deep link found.");
                    }
                }
            });

Into debug, I can see that result.getStatus() returns CANCELED, but the click on lick open the app correctly.

Where I'm wrong?

CeccoCQ avatar Jun 04 '16 19:06 CeccoCQ

@CeccoCQ can you provide the output of adb logcat while this is happening?

samtstern avatar Jun 06 '16 22:06 samtstern

@samtstern Sure.

06-07 11:04:25.969 8446-8446/com.myproject.deeplink D/FirebaseApp: Notifying background state change listeners.
06-07 11:04:25.989 8446-8446/com.myproject.deeplink D/AutoManageHelper: starting AutoManage for client 0 false false
06-07 11:04:25.989 8446-8446/com.myproject.deeplink D/Activity: performCreate Call Injection manager
06-07 11:04:25.999 8446-8446/com.myproject.deeplink D/AutoManageHelper: onStart true {0=com.google.android.gms.internal.zznr$zza@2925ce00}
06-07 11:04:25.999 8446-8446/com.myproject.deeplink I/InjectionManager: dispatchOnViewCreated > Target : com.myproject.deeplink.StartActivity isFragment :false
06-07 11:04:26.019 8446-8446/com.myproject.deeplink D/PhoneWindow: *FMB* installDecor mIsFloating : false
06-07 11:04:26.019 8446-8446/com.myproject.deeplink D/PhoneWindow: *FMB* installDecor flags : -2139029248
06-07 11:04:26.029 8446-8446/com.myproject.deeplink D/SecWifiDisplayUtil: Metadata value : SecSettings2
06-07 11:04:26.029 8446-8446/com.myproject.deeplink D/PhoneWindow: *FMB* isFloatingMenuEnabled mFloatingMenuBtn : null
06-07 11:04:26.029 8446-8446/com.myproject.deeplink D/PhoneWindow: *FMB* isFloatingMenuEnabled return false
06-07 11:04:26.049 8446-8446/com.myproject.deeplink D/SRIB_DCS: log_dcs ThreadedRenderer::initialize entered! 
06-07 11:04:26.049 8446-9701/com.myproject.deeplink D/mali_winsys: new_window_surface returns 0x3000,  [1440x2560]-format:1
06-07 11:04:26.129 8446-8446/com.myproject.deeplink I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@e49947e time:697302451
06-07 11:04:26.209 8446-8446/com.myproject.deeplink D/FirebaseDL: getInvitation: no deep link found.
06-07 11:04:26.209 8446-8446/com.myproject.deeplink D/DL: Start with Plain
06-07 11:04:26.339 8446-8446/com.myproject.deeplink I/Timeline: Timeline: Activity_launch_request id:com.myproject.deeplink time:697302664
06-07 11:04:26.349 8446-8446/com.myproject.deeplink D/DL: Start without DL
06-07 11:04:26.349 8446-8446/com.myproject.deeplink I/Timeline: Timeline: Activity_launch_request id:com.myproject.deeplink time:697302674

My AndroidManifest.xml

<activity
            android:name="com.myproject.deeplink.StartActivity" >
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data
                    android:host="aqld.it"
                    android:scheme="http" />
                <data
                    android:host="aqld.it"
                    android:scheme="https" />
            </intent-filter>
        </activity>

CeccoCQ avatar Jun 07 '16 09:06 CeccoCQ

Sorry @CeccoCQ those logs don't include much. Could you provide the full output of adb logcat for ~15 seconds before and after the operation.

If it's too large to paste here, feel free to use a pastebin or github gist.

samtstern avatar Jun 07 '16 23:06 samtstern

This is the entire log:

06-08 09:20:51.425 24237-28036/com.myproject.deeplink V/FA: Activity paused, time: 1437902373
06-08 09:20:52.145 24237-24237/com.myproject.deeplink W/EventBus: Subscriber to unregister was not registered before: class com.myproject.deeplink.LoginActivity
06-08 09:20:52.165 24237-28036/com.myproject.deeplink W/FA: Value is too long; discarded. Value kind, name, value length: param, item_id, 51
06-08 09:20:52.175 24237-28036/com.myproject.deeplink D/FA: Logging event (FE): select_content, Bundle[{item_name=LoginActivity, _o=app, _ev=item_id, _err=4, content_type=SIGNIN}]
06-08 09:20:52.175 24237-28036/com.myproject.deeplink V/FA: Using measurement service
06-08 09:20:52.175 24237-28036/com.myproject.deeplink V/FA: Connecting to remote service
06-08 09:20:52.175 24237-24237/com.myproject.deeplink V/ActivityThread: updateVisibility : ActivityRecord{3f172931 token=android.os.BinderProxy@cdd7994 {com.myproject.deeplink/com.myproject.deeplink.LoginActivity}} show : false
06-08 09:20:52.175 24237-24237/com.myproject.deeplink D/FirebaseApp: Notifying background state change listeners.
06-08 09:20:52.325 24237-28036/com.myproject.deeplink D/FA: Connected to remote service
06-08 09:20:52.325 24237-28036/com.myproject.deeplink V/FA: Processing queued up service tasks: 1
06-08 09:20:52.435 24237-28036/com.myproject.deeplink D/FA: Application backgrounded. Logging engagement
06-08 09:20:52.435 24237-28036/com.myproject.deeplink D/FA: Logging event (FE): _e, Bundle[{_o=auto, _et=82691}]
06-08 09:20:56.455 24237-25759/com.myproject.deeplink I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
06-08 09:20:56.505 24237-25759/com.myproject.deeplink I/System.out: KnoxVpnUidStorageknoxVpnSupported API value returned is false
06-08 09:20:57.435 24237-28036/com.myproject.deeplink V/FA: Inactivity, disconnecting from AppMeasurementService
06-08 09:21:23.635 24237-24237/com.myproject.deeplink D/FirebaseApp: Notifying background state change listeners.
06-08 09:21:23.635 24237-24237/com.myproject.deeplink V/FA: onActivityCreated
06-08 09:21:23.655 24237-24237/com.myproject.deeplink V/StartActivity: onCreate
06-08 09:21:23.675 24237-24237/com.myproject.deeplink D/AutoManageHelper: starting AutoManage for client 0 false false
06-08 09:21:23.675 24237-24237/com.myproject.deeplink D/Activity: performCreate Call Injection manager
06-08 09:21:23.685 24237-24237/com.myproject.deeplink D/AutoManageHelper: onStart true {0=com.google.android.gms.internal.zznr$zza@2902909c}
06-08 09:21:23.685 24237-24237/com.myproject.deeplink I/InjectionManager: dispatchOnViewCreated > Target : com.myproject.deeplink.StartActivity isFragment :false
06-08 09:21:23.685 24237-28036/com.myproject.deeplink V/FA: Activity resumed, time: 1437934636
06-08 09:21:23.715 24237-24237/com.myproject.deeplink D/PhoneWindow: *FMB* installDecor mIsFloating : false
06-08 09:21:23.715 24237-24237/com.myproject.deeplink D/PhoneWindow: *FMB* installDecor flags : -2139029248
06-08 09:21:23.725 24237-24237/com.myproject.deeplink D/SecWifiDisplayUtil: Metadata value : SecSettings2
06-08 09:21:23.725 24237-24237/com.myproject.deeplink D/PhoneWindow: *FMB* isFloatingMenuEnabled mFloatingMenuBtn : null
06-08 09:21:23.725 24237-24237/com.myproject.deeplink D/PhoneWindow: *FMB* isFloatingMenuEnabled return false
06-08 09:21:23.735 24237-24237/com.myproject.deeplink D/SRIB_DCS: log_dcs ThreadedRenderer::initialize entered! 
06-08 09:21:23.735 24237-25841/com.myproject.deeplink D/mali_winsys: new_window_surface returns 0x3000,  [1440x2560]-format:1
06-08 09:21:23.795 24237-24237/com.myproject.deeplink I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@2b9f3e7a time:746299271
06-08 09:21:23.805 24237-24237/com.myproject.deeplink D/FirebaseDL: getInvitation: no deep link found.
06-08 09:21:23.805 24237-24237/com.myproject.deeplink D/DL: Start with Plain
06-08 09:21:23.815 24237-24237/com.myproject.deeplink D/DL: Start without DL
06-08 09:21:23.815 24237-24237/com.myproject.deeplink I/Timeline: Timeline: Activity_launch_request id:com.myproject.deeplink time:746299294
06-08 09:21:23.835 24237-28036/com.myproject.deeplink V/FA: Activity paused, time: 1437934786
06-08 09:21:23.855 24237-24237/com.myproject.deeplink V/FA: onActivityCreated
06-08 09:21:23.855 24237-24237/com.myproject.deeplink D/PhoneWindow: *FMB* installDecor mIsFloating : false
06-08 09:21:23.855 24237-24237/com.myproject.deeplink D/PhoneWindow: *FMB* installDecor flags : -2139028224
06-08 09:21:23.995 24237-24237/com.myproject.deeplink D/Activity: performCreate Call Injection manager
06-08 09:21:23.995 24237-24237/com.myproject.deeplink I/InjectionManager: dispatchOnViewCreated > Target : com.myproject.deeplink.SplashscreenActivity isFragment :false
06-08 09:21:23.995 24237-28036/com.myproject.deeplink V/FA: Activity resumed, time: 1437934943
06-08 09:21:23.995 24237-24237/com.myproject.deeplink D/SecWifiDisplayUtil: Metadata value : SecSettings2
06-08 09:21:23.995 24237-24237/com.myproject.deeplink D/PhoneWindow: *FMB* isFloatingMenuEnabled mFloatingMenuBtn : null
06-08 09:21:23.995 24237-24237/com.myproject.deeplink D/PhoneWindow: *FMB* isFloatingMenuEnabled return false
06-08 09:21:24.025 24237-24237/com.myproject.deeplink D/SRIB_DCS: log_dcs ThreadedRenderer::initialize entered! 
06-08 09:21:24.025 24237-25841/com.myproject.deeplink D/mali_winsys: new_window_surface returns 0x3000,  [1440x2560]-format:1
06-08 09:21:24.085 24237-24237/com.myproject.deeplink I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@3c03cef6 time:746299568
06-08 09:21:27.995 24237-24237/com.myproject.deeplink I/Timeline: Timeline: Activity_launch_request id:com.myproject.deeplink time:746303472
06-08 09:21:28.005 24237-28036/com.myproject.deeplink V/FA: Activity paused, time: 1437938956
06-08 09:21:28.035 24237-24237/com.myproject.deeplink V/FA: onActivityCreated
06-08 09:21:28.035 24237-24237/com.myproject.deeplink D/PhoneWindow: *FMB* installDecor mIsFloating : false
06-08 09:21:28.035 24237-24237/com.myproject.deeplink D/PhoneWindow: *FMB* installDecor flags : -2139029248
06-08 09:21:28.095 24237-24237/com.myproject.deeplink I/TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead.
06-08 09:21:28.105 24237-24237/com.myproject.deeplink I/TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead.
06-08 09:21:28.125 24237-24237/com.myproject.deeplink D/PhoneWindow: *FMB* installDecor mIsFloating : true
06-08 09:21:28.125 24237-24237/com.myproject.deeplink D/PhoneWindow: *FMB* installDecor flags : 8388610
06-08 09:21:28.135 24237-24237/com.myproject.deeplink I/TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead.
06-08 09:21:28.145 24237-24237/com.myproject.deeplink D/PhoneWindow: *FMB* installDecor mIsFloating : true
06-08 09:21:28.145 24237-24237/com.myproject.deeplink D/PhoneWindow: *FMB* installDecor flags : 8388610
06-08 09:21:28.145 24237-24237/com.myproject.deeplink D/Activity: performCreate Call Injection manager
06-08 09:21:28.165 24237-24237/com.myproject.deeplink I/InjectionManager: dispatchOnViewCreated > Target : com.myproject.deeplink.LoginActivity isFragment :false
06-08 09:21:28.165 24237-28036/com.myproject.deeplink V/FA: Activity resumed, time: 1437939116
06-08 09:21:28.165 24237-24237/com.myproject.deeplink D/SecWifiDisplayUtil: Metadata value : SecSettings2
06-08 09:21:28.175 24237-24237/com.myproject.deeplink D/PhoneWindow: *FMB* isFloatingMenuEnabled mFloatingMenuBtn : null
06-08 09:21:28.175 24237-24237/com.myproject.deeplink D/PhoneWindow: *FMB* isFloatingMenuEnabled return false
06-08 09:21:28.205 24237-24237/com.myproject.deeplink D/SRIB_DCS: log_dcs ThreadedRenderer::initialize entered! 
06-08 09:21:28.205 24237-25841/com.myproject.deeplink D/mali_winsys: new_window_surface returns 0x3000,  [1440x2560]-format:1
06-08 09:21:28.255 24237-24237/com.myproject.deeplink I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@213fffde time:746303735
06-08 09:21:28.755 24237-25759/com.myproject.deeplink I/System.out: (HTTPLog)-Static: isSBSettingEnabled false

This is the StartActivity code:

public class StartActivity extends RoboFragmentActivity {

    @Inject
    MainPreferenceUtils mainPreferenceUtils;

    private GoogleApiClient mGoogleApiClient;
    private boolean hasGooglePlayServicesInstalled = true;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.v("StartActivity", "onCreate");

        // Firebase
        GoogleApiClient.Builder builder = new GoogleApiClient.Builder(this)
                .enableAutoManage(this, new GoogleApiClient.OnConnectionFailedListener() {
                    @Override
                    public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
                        Log.w("StartActivity", "onConnectionFailed:" + connectionResult);
                        hasGooglePlayServicesInstalled = false;
                    }
                })
                .addApi(AppInvite.API);
        mGoogleApiClient = builder.build();

    }

    @Override
    protected void onResume() {
        super.onResume();

            if(!hasGooglePlayServicesInstalled) {
                // Plain Deep link
                handlePlainDeepLink();

                // No Deep Link
                Log.d("DL", "Start without DL");
                Class activity = SplashscreenActivity.class;
                if (mainPreferenceUtils.getAccessToken() != null) {
                    activity = MainActivity.class;
                }
                goToActivity(activity);
                return;
            }

            // Firebase Deep Link
            final DeferredObject firebaseDeepLink = new DeferredObject();
            handleFirebaseDeepLink(firebaseDeepLink);
            Promise p = firebaseDeepLink.promise();
            p.then(new DoneCallback() {
                @Override
                public void onDone(Object result) {
                    FirebaseInvitation firebaseInvitation = (FirebaseInvitation) result;
                    Log.d("DL", "Start with Firebase");

                    // TODO:
                }
            }).fail(new FailCallback() {
                @Override
                public void onFail(Object result) {
                    Log.d("FirebaseDL", "getInvitation: no deep link found.");

                    // Plain Deep link
                    handlePlainDeepLink();

                    // Normal Flow
                    Log.d("DL", "Start without DL");
                    Class activity = SplashscreenActivity.class;
                    if (mainPreferenceUtils.getAccessToken() != null) {
                        activity = MainActivity.class;
                    }
                    goToActivity(activity);
                }
            });

    }

    @Override
    public void finish() {
        overridePendingTransition(0, 0);
        super.finish();
    }

    private void handlePlainDeepLink() {
        Uri data = getIntent().getData();
        if (data != null) {
            Log.d("DL", "Start with Plain");

            mainPreferenceUtils.setDeepLinkUri(data);

            if (mainPreferenceUtils.getAccessToken() != null) {
                Intent activityIntent = new IntentBuilder()
                        .context(this)
                        .activity(MainActivity.class)
                        .action(MainActivity.ACTION_HANDLE_DEEP_LINK)
                        .flags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP)
                        .data(data)
                        .build();
                startActivity(activityIntent);
            }

            return;
        }
    }

    private void handleFirebaseDeepLink(final DeferredObject firebaseDeepLink) {

        // Firebase DeepLink
        AppInvite.AppInviteApi.getInvitation(mGoogleApiClient, this, false).setResultCallback(
                new ResultCallback<AppInviteInvitationResult>() {
                    @Override
                    public void onResult(@NonNull AppInviteInvitationResult result) {
                        if (result.getStatus().isSuccess()) {
                            // Extract deep link from Intent
                            Intent intent = result.getInvitationIntent();
                            String deepLink = AppInviteReferral.getDeepLink(intent);

                            // Handle the deep link. For example, open the linked
                            // content, or apply promotional credit to the user's
                            // account.
                            firebaseDeepLink.resolve(new FirebaseInvitation(intent, deepLink));
                            return;
                        }

                        firebaseDeepLink.reject(null);
                    }
                });
    }


    private void goToActivity(Class activityClass) {
        Intent intent = new IntentBuilder()
                .context(this)
                .activity(activityClass)
                .flags(Intent.FLAG_ACTIVITY_NO_ANIMATION, Intent.FLAG_ACTIVITY_NEW_TASK)
                .build();
        overridePendingTransition(0, 0);
        startActivity(intent);
        finish();
    }

    private class FirebaseInvitation {
        public Intent invitationIntent;
        public String deepLink;

        public FirebaseInvitation(Intent invitationIntent, String deepLink) {
            this.invitationIntent = invitationIntent;
            this.deepLink = deepLink;
        }
    }
}

CeccoCQ avatar Jun 08 '16 07:06 CeccoCQ

@CeccoCQ can you double-check that the SHA1 you put in the Firebase console matches the SHA1 of your APK?

samtstern avatar Jun 08 '16 23:06 samtstern

The link is: https://wft4z.app.goo.gl/?link=https://aqld.it/testlink/112972&al=aqld://test/about?test%3D17363&apn=com.project.mydeeplink

In the firebase console I've added: schermata 2016-06-09 alle 08 25 46

And this is the check with the keytool -exportcert -list -v \ -alias <your-key-name> -keystore <path-to-production-keystore> schermata 2016-06-09 alle 08 27 34

I don't know what to do...

CeccoCQ avatar Jun 09 '16 06:06 CeccoCQ

Any idea about my issue?

CeccoCQ avatar Jun 12 '16 06:06 CeccoCQ

Same problem and I still do not fix it

ivandiazmolina avatar Jun 14 '16 07:06 ivandiazmolina

@CeccoCQ sorry for the delayed response and thank you for the SHA info. I am still not 100% sure what the issue is but I am looking into it. Also just to be sure, are you using a device with Google Play Services version 9.0.80 or higher?

samtstern avatar Jun 15 '16 14:06 samtstern

@samtstern Yes, I'm using the latest version 9.0.83

CeccoCQ avatar Jun 15 '16 15:06 CeccoCQ

Same issue here as well

85simo avatar Jun 16 '16 08:06 85simo

Same issues for me, same code and logcat as CeccoCQ

giannign1 avatar Jun 16 '16 17:06 giannign1

+1

nottix avatar Jun 17 '16 17:06 nottix

+1

manuelcugliari avatar Jun 17 '16 17:06 manuelcugliari

I have the same problem, any news about it?

Seidak avatar Jul 06 '16 10:07 Seidak

I'm also experiencing the same issue. So far I've wasted a whole day on this.

JasonSheedy avatar Jul 07 '16 23:07 JasonSheedy

Got it working by adding SHA-1 key. However, if this causes dynamic links to fail, why is adding the SHA-1 key marked as optional in the console?

JasonSheedy avatar Jul 12 '16 00:07 JasonSheedy

@JasonSheedy that's a very good question, let me look into that. Glad you solved your issue!

samtstern avatar Jul 12 '16 01:07 samtstern

@JasonSheedy from what I can see the console says the SHA1 is required for App Invites / Dynamic Links. firebase_console

I think the real bug here is that the error message on Android is so opaque. CANCELED should tell you if it's a SHA1 issue. I'll see what I can do about that!

samtstern avatar Jul 12 '16 16:07 samtstern

Hi, I still have the issue.

I've a project with 4 build types, that I named: .dev, .staging, .debug, .release as suffix. So I've 4 different apks for my application.

For each type, I've created a specific alias in my keystore file and I've a different SHA1. In the firebase console, in the Project settings I've 4 different app and I added the relative SHA1.

Nothing works, same error "Intent CANCELED".

CeccoCQ avatar Jul 12 '16 16:07 CeccoCQ