Ad

I Cannot Retrieve Dynamic Link From Firebase Through My Application As Pendingdynamiclinkdata Is Null

I am trying to retrieve the deeplink URL from firebase but always shows me null.

i have added below code in manifest and i have also tried with the short dynamic URL i.e. https://example555.page.link/y6N7 but still its show me null.

            <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="example555.page.link"
                android:scheme="https"
                 />

        </intent-filter>

Here is my code of retrieving dynamic link :

             FirebaseDynamicLinks.getInstance()
             .getDynamicLink(getIntent())
             .addOnSuccessListener(this, new 
             OnSuccessListener<PendingDynamicLinkData>() {
            @Override
             public void onSuccess(PendingDynamicLinkData 
             pendingDynamicLinkData) {
              Uri deepLink = null;

                if (pendingDynamicLinkData != null) {
                    deepLink = pendingDynamicLinkData.getLink();
                }
            }
        })
        .addOnFailureListener(this, new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                Log.w(TAG, "getDynamicLink:onFailure", e);
            }
        });
Ad

Answer

ok so after banging my head for so many hours i found a solution which helped me in getting the solution :

so ill start from beginning : 1. create a dynamic link. 2. add following code to your manifest

      <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="example555.page.link"
            android:scheme="https"/>

    </intent-filter>
  1. add this code in you Main activity :

           FirebaseAnalytics mFirebaseAnalytics;
            mFirebaseAnalytics=FirebaseAnalytics.getInstance(this);
    
            FirebaseDynamicLinks.getInstance()
            .getDynamicLink(getIntent())
            .addOnSuccessListener(this, new 
             OnSuccessListener<PendingDynamicLinkData>() {
                @Override
                public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
                    // Get deep link from result (may be null if no link is found)
                    Uri deepLink = null;
    
                    if (pendingDynamicLinkData != null) {
                        deepLink = pendingDynamicLinkData.getLink();
    
                        Log.w("deepLink", "" + deepLink);
                   String cn=String.valueOf(deepLink.getQueryParameters("utm_campaign"));
                        String cm = String.valueOf(deepLink. getQueryParameters("utm_medium"));
                        String cs = String.valueOf(deepLink.getQueryParameters("utm_source"));
    
                        if (cs != null && cn != null) {
                            Bundle params = new Bundle();
                            params.putString(FirebaseAnalytics.Param.CAMPAIGN, cn);
                            params.putString(FirebaseAnalytics.Param.MEDIUM, cm);
                            params.putString(FirebaseAnalytics.Param.SOURCE, cs);
    
                            mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.CAMPAIGN_DETAILS, params);
                            mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.APP_OPEN, params);
                        }
    
    
                    }
                }
            })
            .addOnFailureListener(this, new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    Log.w("TAG", "getDynamicLink:onFailure", e);
                }
            });
    
  2. now its time to test your application: google search your url i.e example555.page.link after that it will redirect you to application and you fill and your out put. if this works than thankyou.

Ad
source: stackoverflow.com
Ad