Add parameter to Firebase Dynamic Links

旧时模样 提交于 2019-11-29 08:46:21
AarónBC.

SHORT ANSWER: Using query parameters instead of path variables you could use the getQueryParameter method from the Uri object returned by pendingDynamicLinkData.getLink()


What i've been doing is using query parameters instead of path variables.

Instead of sending http://www.myapp.com/offer/123, i'm sending something like http://www.myapp.com/?offer=123

To add parameters dynamically i'm just concatenating strings: "http://www.myapp.com/?offer=" + myValue

This URL is in turn a query parameter of the dynamic link created in firebase:

String url = "https://YourDynamicLinkIdentifier.app.goo.gl/?link=https://myapp.com?offer=" 
+ myOfferVar 
+ "&apn=com.your.apn"; // << Dont forget to change this too

And this resulting URL is the one i send to the url shortener.

Then in the callback onSuccess(PendingDynamicLinkData pendingDynamicLinkData) call getLink() of pendingDynamicLinkData as you're already doing.

Now that you have a Uri object, you can easily get the parameter by calling the method getQueryParameter("offer").

if (pendingDynamicLinkData != null) {
     deepLink = pendingDynamicLinkData.getLink();
     String offerKey = deepLink.getQueryParameter("offer");

NOTE: In case you still prefer to use the path variable, you could get the last segment of the Uri path. See How to obtain the last path segment of an uri

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