问题描述
Uri BASE_URI = Uri.parse(http ://example.com/);
String packageName = getBaseContext()。getPackageName(); ()。()。trim()+%3DrequestID =+ requestID.getText()。toString()。trim()+ 。%3Dextra1 = + extra1.getText()的toString()修剪()+ %3Dextra2 =+ extra2.getText()的toString()修剪())建立();
String encodedUri = URLEncoder.encode(APP_URI.toString(),UTF-8);
Uri deepLink = Uri.parse(https://appcode.app.goo.gl/?link=+ encodedUri +& apn =+ packageName +& amv =+16+&广告=+ 0);
然后我与另一个用户分享,他正在收到这个链接: http://example.com/-KcP1YHgGsg3tVYybX8b%253DrequestID%3D-KcP1YHgGsg3tVYybX8b%253Dextra1%3Dtext1%253Dextra2%3D3%253Dtext2
。
然后使用下面的代码我试图从这里获取查询参数(链接中的额外参数):
$ $ $ p $ bo $ autoLaunchDeepLink = false;
AppInvite.AppInviteApi.getInvitation(mGoogleApiClient,this,autoLaunchDeepLink)
.setResultCallback(
new ResultCallback< AppInviteInvitationResult>(){
@Override $ b $ public void onResult(@ NonNull AppInviteInvitationResult结果){
if(result.getStatus()。isSuccess()){
//从Intent提取深层链接
Intent intent = result.getInvitationIntent();
(深度链接);
字符串requestId = uri.getQueryParameter(request ID);
Log.d(requestId123,requestId);
} else {
Log.d(getInvitation,getInvitation:no deep link found。);
}
}
});
但是应用程序崩溃显示: java.lang.NullPointerException:println因为
uri.getQueryParameter(requestID);
正在返回 null
,所以需要一个消息
我该做什么错了,我怎样才能从深层链接
?
请让我知道。
这是你的url
$ $ c $ Uri APP_URI = BASE_URI.buildUpon().path(requestID.getText().toString()。trim()+%3DrequestID = + requestID.getText()。的toString()。修剪()+ %3Dextra1 = + extra1.getText()。的toString()。修剪()+ %3Dextra2 =+ extra2.getText()。的toString( ).trim())。build();
如果你解码这个Url,你将会收到类似的东西
http://www.airbanq.com?name=45=extra1=45=extra2=12=extra3=455
此值%3D
等于 =
。要连接查询字符串中的值,您需要使用此&;,也许您可以尝试避免编码和解码,然后再试一次。我在另一个线程中提出了这个选项,因为这对我的老版本的FIrebase来说工作得很好。
这是你的空错误的主要原因,基本上你试图从这个 更新1 这段代码是基于你现在所拥有的
http://www.airbanq.com?name=45=extra1=45=extra2=12=extra3=455 $ c $创建一个像这样的链接
http://www.airbanq.com?name=45&extra1=45& extra2 = 12&extra3 = 455
并且让我知道。
我将与您分享一些代码,希望这可以解决你的问题。
这个第一部分是创建URL,并添加一些参数,你可以看到
pre $ U $ 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);
最后一部分只是接收深层链接并读取值
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()){
//从意图提取信息
意图intent = result.getInvitationIntent();
字符串deepLink = AppInviteReferral.getDeepLink(意图);
字符串invitationId = AppInviteReferral.getInvitationI d(意向);
尝试{
deepLink = URLDecoder.decode(deepLink,UTF-8);
} catch(UnsupportedEncodingException e){
e.printStackTrace();
}
Uri uri = Uri.parse(deepLink);
字符串requestId = uri.getQueryParameter(requestID);
字符串requestId2 = uri.getQueryParameter(extra2);
//因为autoLaunchDeepLink = true,所以我们不需要在这里做任何事情
//但是我们可以将它设置为false并手动选择
//一个要启动的Activity来处理这里的深层次的联系。
// ...
}
}
});
最后这是清单
< activity
android:name =com.google.firebase.quickstart.invites.MainActivity
android:label =@ string / app_name>
< intent-filter>
< category android:name =android.intent.category.DEFAULT/>
< category android:name =android.intent.category.BROWSABLE/>
< data android:host =example.comandroid:scheme =http/>
< data android:host =example.comandroid:scheme =https/>
< / intent-filter>
< / activity>
希望这可以解决您的问题
I'm creating a Firebase dynamic/deep link manually like this:
Uri BASE_URI = Uri.parse("http://example.com/");
String packageName = getBaseContext().getPackageName();
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();
String encodedUri = URLEncoder.encode(APP_URI.toString(), "UTF-8");
Uri deepLink = Uri.parse("https://appcode.app.goo.gl/?link="+encodedUri+"&apn="+packageName+"&amv="+16+"&ad="+0);
and then I'm sharing it with another user and he is receiving this link: http://example.com/-KcP1YHgGsg3tVYybX8b%253DrequestID%3D-KcP1YHgGsg3tVYybX8b%253Dextra1%3Dtext1%253Dextra2%3D3%253Dtext2
.
Then using following code I'm trying to get the query parameters (extra parameters in the link) from here:
boolean autoLaunchDeepLink = false;
AppInvite.AppInviteApi.getInvitation(mGoogleApiClient, this, autoLaunchDeepLink)
.setResultCallback(
new ResultCallback<AppInviteInvitationResult>() {
@Override
public void onResult(@NonNull AppInviteInvitationResult result) {
if (result.getStatus().isSuccess()) {
// Extract deep link from Intent
Intent intent = result.getInvitationIntent();
final String deepLink = AppInviteReferral.getDeepLink(intent);
Log.d("deepLinkMainActivity", deepLink);
Uri uri = Uri.parse(deepLink);
String requestId = uri.getQueryParameter("requestID");
Log.d("requestId123", requestId);
} else {
Log.d("getInvitation", "getInvitation: no deep link found.");
}
}
});
but the app is getting crashed showing: java.lang.NullPointerException: println needs a message
because uri.getQueryParameter("requestID");
is returning null
.
What am I doing wrong and How can I get the query parameters from the deep-link
?
Please let me know.
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 thishttp://www.airbanq.com?name=45=extra1=45=extra2=12=extra3=455
Create a link like thishttp://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
这篇关于无法查询存储在Firebase动态/深层链接中的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!