pendingDynamicLinkData显示为null

时间:2018-02-25 18:19:44

标签: android dynamic-linking

我正在开发一个可以分享并获得奖励的应用程序,因此我使用动态链接的概念,以便将邀请者的信息存储在该链接中,然后获得奖励。但PendingDynamicLinkData在参考后安装应用程序时返回null。

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

点击按钮分享并赚取

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

清单

    <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>

提前谢谢你,你的帮助很明显

1 个答案:

答案 0 :(得分:1)

Possbile原因:

<强> 1。包名称不正确

您确定自己的应用包名称为com.example.android     提到的

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

中的

此处所需的软件包名称是应用级applicationId文件中的build.gradle

<强> 2。由于 DynamicLinkDomain

而导致网址格式错误

我的网址不正确,因为结果是https://app_code.app.goo.gl?..... 我必须将domain更改为app_code.app.goo.gl/(现在在末尾附加正斜杠),然后它才成为有效的URL。

第3。由于编码的网址

,网址形成不正确

执行String invitationLink = mInvitationUrl.toString();会转换您的深层链接,即"https://drive.google.com/open?....."更改为"https%3A%2F%2Fdrive.goo...."。为此,您需要使用URLDecoder.decode(mInvitationUrl.toString(), "UTF-8");方法。这将返回与所需的有效URL相同的String

提示

您无需在android:host=""的{​​{1}}下提供完整的网址。只需AndroidManifest.xml,即可让您的应用打开所有android:host="drive.google.com"个网址。