pendingDynamicLinkData shows null
Asked Answered
I

1

7

I am developing an app which can share and been reward so I use the concept of the dynamic link so to store the information of inviter in that link and later be rewarded. but the PendingDynamicLinkData return null on installing the app after reffered.

MainActivity

    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.d("successpra", "onSuccess: ");
                        String referrerUid = deepLink.getQueryParameter("invitedby");
                        Toast.makeText(SplashActivity.this,referrerUid,Toast.LENGTH_SHORT).show();

                    }
                    else
                        Toast.makeText(SplashActivity.this,"referrerUid",Toast.LENGTH_SHORT).show();
                }
            });

onclick button of share and earn

        FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
        String uid = user.getUid();
        Log.d("prashu",uid);
        String link = "https://drive.google.com/open?id=1XUPfiBGCSydmgwEE7E-IRatAeGVuMbOr&?invitedby="+uid;
        FirebaseDynamicLinks.getInstance().createDynamicLink()
                .setLink(Uri.parse(link))
                .setDynamicLinkDomain("nw8y9.app.goo.gl")
                .setAndroidParameters(
                        new DynamicLink.AndroidParameters.Builder("com.example.android")
                                .setMinimumVersion(125)
                                .build())
                .setIosParameters(
                        new DynamicLink.IosParameters.Builder("com.example.ios")
                                .setAppStoreId("123456789")
                                .setMinimumVersion("1.0.1")
                                .build())
                .buildShortDynamicLink()
                .addOnSuccessListener(new OnSuccessListener<ShortDynamicLink>() {
                    @Override
                    public void onSuccess(ShortDynamicLink shortDynamicLink) {
                        Uri mInvitationUrl = shortDynamicLink.getShortLink();
                        Log.d("prashu",mInvitationUrl.toString());
                        String referrerName =FirebaseAuth.getInstance().getCurrentUser().getDisplayName();
                        String subject = String.format("%s wants you to play MyExampleGame!", referrerName);
                        String invitationLink = mInvitationUrl.toString();
                        String msg = "Let's play MyExampleGame together! Use my referrer link: "
                                + invitationLink;
                        String msgHtml = String.format("<p>Let's play MyExampleGame together! Use my "
                                + "<a href=\"%s\">referrer link</a>!</p>", invitationLink);

                        Intent intent = new Intent(Intent.ACTION_SEND);
                        intent.setType("text/plain");
                        intent.putExtra(Intent.EXTRA_SUBJECT, subject);
                        intent.putExtra(Intent.EXTRA_TEXT, msg);
                        intent.putExtra(Intent.EXTRA_HTML_TEXT, msgHtml);
                        if (intent.resolveActivity(getPackageManager()) != null) {
                            startActivity(intent);
                        }
                    }
                });

Manifest

    <activity android:name=".MainActivity">
    <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="drive.google.com/open?id=1xupfibgcsydmgwee7e-irataegvumbor" android:scheme="http"/>
        <data android:host="drive.google.com/open?id=1xupfibgcsydmgwee7e-irataegvumbor" android:scheme="https"/>
    </intent-filter>
    </activity>

thank u in advance, ur help is appreciable

Ironmonger answered 25/2, 2018 at 18:19 Comment(0)
R
4

Possbile causes:

1. Incorrect package name

Are you sure your app's package name is com.example.android as mentioned

in new DynamicLink.AndroidParameters.Builder("com.example.android")

The required package name over here is your applicationId in the app level build.gradle file.

2. Incorrect URL formation due to DynamicLinkDomain

My URL wasn't correct as it turned out to be https://app_code.app.goo.gl?..... I had to change the domain to app_code.app.goo.gl/ (forward slash appended at the end now) and only then it became a valid URL.

3. Incorrect URL formation due to encoded URL

Performing String invitationLink = mInvitationUrl.toString(); would convert your deep link i.e. "https://drive.google.com/open?....." to change to "https%3A%2F%2Fdrive.goo....". For that you'd need to use the URLDecoder.decode(mInvitationUrl.toString(), "UTF-8"); method. This would return a String that would the same as the valid URL required.

Tip:

You don't need to provide the complete url under android:host="" in the AndroidManifest.xml. Just android:host="drive.google.com" would do as that would allow your app to open all drive.google.com URLs.

Rye answered 20/4, 2018 at 6:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.