Unable to query parameters stored in a Firebase dynamic/deep-link

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 09:47:50


This i your url
Uri APP_URI = BASE_URI.buildUpon().path(requestID.getText().toString().trim()+"%3DrequestID="+requestID.getText().toString().trim()+"%3Dextra1="+extra1.getText().toString().trim()+"%3Dextra2="+extra2.getText().toString().trim()).build();

If you decode this Url you are going to receive something like this

http://www.airbanq.com?name=45=extra1=45=extra2=12=extra3=455

This value %3D is equal to a =. To concatenate values in a query string you need to use this &, maybe you can try to avoid the encoding and decoding and try again. I suggested that option, in the other thread, because that was working fine to me with an older version of FIrebase.

That's the main reason behind of your null error, basically you are trying to get a query string from this http://www.airbanq.com?name=45=extra1=45=extra2=12=extra3=455

Create a link like this http://www.airbanq.com?name=45&extra1=45&extra2=12&extra3=455 and let me know. After this change with your code this will be works fine.

Update 1
I will share with you some code, hope this can solve your problem.

This code is based on what you have right now
This first part is to create the URL and add some parameters as you can see

Uri BASE_URI = Uri.parse("http://example.com/");

Uri APP_URI = BASE_URI.buildUpon().appendQueryParameter("requestID", "200").
                    appendQueryParameter("extra1", "value").
                    appendQueryParameter("extra2", "value").build();


String encodedUri = null;
try {
   encodedUri = URLEncoder.encode(APP_URI.toString(), "UTF-8");
} catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
Uri deepLink = Uri.parse("https://app.app.goo.gl/?link="+encodedUri+"&apn=com.xx.xx.dev");

This last part is just to receive the deeplink and read the values

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

                                    try {
                                        deepLink = URLDecoder.decode(deepLink, "UTF-8");
                                    } catch (UnsupportedEncodingException e) {
                                        e.printStackTrace();
                                    }
                                    Uri uri = Uri.parse(deepLink);
                                    String requestId = uri.getQueryParameter("requestID");
                                    String requestId2 = uri.getQueryParameter("extra2");

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

And finally this is the manifest

<activity
            android:name="com.google.firebase.quickstart.invites.MainActivity"
            android:label="@string/app_name">
            <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="example.com" android:scheme="http"/>
                <data android:host="example.com" android:scheme="https"/>

            </intent-filter>
        </activity>

Hope this can solve your problems

Elias Fazel

If you want to extract a text from the link text, use regex or get at specific indexof text. This is how you can get the data from invitation: Reference

Intent intent = result.getInvitationIntent();
String deepLink = AppInviteReferral.getDeepLink(intent);
String invitationId = AppInviteReferral.getInvitationId(intent);

and it s better to paste whole error message.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!