我正在手动创建一个 Firebase 动态/深层链接,如下所示:
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);
然后我与另一个用户分享它,他正在接收这个链接:http://example.com/-KcP1YHgGsg3tVYybX8b%253DrequestID%3D-KcP1YHgGsg3tVYybX8b%253Dextra1%3Dtext1%253Dextra2%3D3%253Dtext2
。
然后使用以下代码,我试图从这里获取查询参数(链接中的额外参数):
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.");
}
}
});
但应用程序正在崩溃显示:java.lang.NullPointerException: println needs a message
因为uri.getQueryParameter("requestID");
正在返回null
。
我做错了什么,如何从deep-link
?
请告诉我。