我正在开发动态链接以共享页面内容,以便在另一设备中的同一应用程序中直接打开它。 创建共享动态链接时,我要添加查询参数“ hotelId”, 但是,当我单击共享链接并尝试打开链接时,应用程序正常打开,但是deepLink.getQueryParameter(“ hotelId”)始终返回null。 这是我的代码:
提供动态链接(DetailActivity)
onCreate(){
...
DynamicLink dynamicLink =
FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLink(Uri.parse("www.example.com"))
.setDynamicLinkDomain("example.page.link/hotelDetail?hotelId="+hotelId)
// Open links with this app on Android
.setAndroidParameters(new
DynamicLink.AndroidParameters.Builder().build())
// Open links with com.example.ios on iOS
.setIosParameters(new
DynamicLink.IosParameters.Builder("com.example.exampleDark").build())
.buildDynamicLink();
Uri dynamicLinkUri = dynamicLink.getUri();
Log.e("DynamicLink -",dynamicLinkUri.toString());
//Share Dynamic Link
try {
URL url = new URL(URLDecoder.decode(myDynamicLink.toString(), "UTF-8"));
Log.i("Share Link", "URL = :"+url.toString());
// [START ddl_share_link]
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Firebase Deep Link");
//String msg = "Hey, check this out: \n" + link;
sendIntent.putExtra(Intent.EXTRA_TEXT, url.toString());
startActivity(sendIntent);
// [END ddl_share_link]
} catch (Exception e) {
e.printStackTrace();
Log.i(TAG, "Could not decode Uri: " + e.getLocalizedMessage());
}
...
}
更新manifest.xml以接收动态链接
<activity
android:name=".DetailActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- [START link_intent_filter] -->
<!-- handle website links -->
<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.page.link" android:scheme="http"/>
<data android:host="example.page.link" android:scheme="https"/>
</intent-filter>
<!-- [END link_intent_filter] -->
</activity>
要从共享URL(DetailActivity)获取动态链接
FirebaseDynamicLinks.getInstance()
.getDynamicLink(getIntent())
.addOnSuccessListener(this, new
OnSuccessListener<PendingDynamicLinkData>() {
@Override
public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
Uri deepLink = null;
if (pendingDynamicLinkData != null) {
deepLink = pendingDynamicLinkData.getLink();
String path = deepLink.getPath();
//if(path.equals("/hotelDetail")){
String hId = deepLink.getQueryParameter("hotelId");
Log.i("Get Parameters", " Hotel = :" + hId + " Offer = :");
} else {
Log.i("Get Parameters", "No Hotel Link");
}
}
})
.addOnFailureListener(this, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.i("Get Parameters", "getDynamicLink:onFailure", e);
}
});
在Firebase控制台上定义的值
URL Link - https://example.page.link/hotelDetail
Dynamic Link - https://example.page.link/hotelDetail?hotelId
共享内容后,我将获得以下链接作为动态链接(共享链接)
https://example.page.link/hotelDetail?hotelId=6q7a99a78d7fb63f330g2w6d?apn=myapp.com.myapp&ibi=com.example.exampleDark&link=www.example.com
我想要的是,当我单击共享链接时,我想从共享链接获取DetailActivity的'hotelId'值。
请有人能帮助我我所缺少的吗? 预先感谢
答案 0 :(得分:3)
很抱歉,您的回答很晚。遇到了同样的问题,所以我把这个留给其他人。
您应该从Intent获取查询参数
GET /myGateway/input \r\n
The
intent.getData().getQueryParameter(hotelId);
将始终为 null ,因为
deepLink.getQueryParameter("hotelId");
将仅返回您的短动态链接
pendingDynamicLinkData.getLink();