13

I have created dynamic link manually and I set some additional parameters on the link, like this:

https://XXXXX.goo.gl/?link=https%3A%2F%2Fairbanq.send.com%2Fsendmoney&apn=com.xxxx.xxxx&amv=1&username=Adri&amount=7.00

But when the app is opened I just get without the additional parameters:

https:// airbanq.send.com/sendmoney

I am using this sample code from:

public String buildDeepLink() {
    // Get the unique appcode for this app.
    String appCode = AirBanqApp.mContext.getString(R.string.app_code);

    // Get this app's package name.
    String packageName = AirBanqApp.mContext.getPackageName();

    // Build the link with all required parameters
    Uri.Builder builder = new Uri.Builder()
            .scheme("https")
            .authority(appCode + ".app.goo.gl")
            .path("/")
            .appendQueryParameter("link", deepLink)
            .appendQueryParameter("apn", packageName);

    // If the deep link is used in an advertisement, this value must be set to 1.
    if (isAd) {
        builder.appendQueryParameter("ad", "1");
    }

    // Minimum version is optional.
    if (minVersion > 0) {
        builder.appendQueryParameter("amv", Integer.toString(minVersion));
    }

    if (!TextUtils.isEmpty(androidLink)) {
        builder.appendQueryParameter("al", androidLink);
    }

    if (!TextUtils.isEmpty(playStoreAppLink)) {
        builder.appendQueryParameter("afl", playStoreAppLink);
    }

    if (!customParameters.isEmpty()) {
        for (Map.Entry<String, String> parameter : customParameters.entrySet()) {
            builder.appendQueryParameter(parameter.getKey(), parameter.getValue());
        }
    }

    // Return the completed deep link.
    return builder.build().toString();
}
4
  • Can you paste some code showing us how you're getting what you're getting? ...just the relevant part. Commented Jul 7, 2016 at 16:58
  • i solve my issue man, thanks i will post my code, before and after the fix Commented Jul 7, 2016 at 18:27
  • We can use Firebase POST URl to generate Refer this answer link Commented Jan 17, 2017 at 12:30
  • Cool, thanks Naveen Commented Jan 17, 2017 at 16:10

2 Answers 2

22

I solved my issue, I assumed the "apn", "username" and "amount" they were part of the parameter "LINK" in the URL, but no when I add the "&". I am adding parts to the main URL, to add parameters to the "LINK" field I need to create first the URL like this:

https://airbanq.send.com/sendmoney?username=Adri&amount=7.00

then use URLEncoder.encode(queryParameters.toString(), "UTF-8"); to generate this:

https%3A%2F%2Fairbanq.send.com%2Fsendmoney%253Fusername%253DAdri%2526amount%253D7.00

and then append to main URL:

https://xxxx.app.goo.gl/?link=https%3A%2F%2Fairbanq.send.com%2Fsendmoney%253Fusername%253DAdri%2526amount%253D7.00&apn=com.airbanq.airbanqapp&amv=1
public String buildDeepLink() {
    // Get the unique appcode for this app.
    String appCode = AirBanqApp.mContext.getString(R.string.app_code);

    // Get this app's package name.
    String packageName = AirBanqApp.mContext.getPackageName();
    String queryParamters = "";
    try {
        queryParamters = generateQueryParameters();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    if (!TextUtils.isEmpty(queryParamters)) {
        deepLink = deepLink + queryParamters;
    }
    // Build the link with all required parameters
    Uri.Builder builder = new Uri.Builder()
            .scheme("https")
            .authority(appCode + ".app.goo.gl")
            .path("/")
            .appendQueryParameter("link", deepLink)
            .appendQueryParameter("apn", packageName);

    // If the deep link is used in an advertisement, this value must be set to 1.
    if (isAd) {
        builder.appendQueryParameter("ad", "1");
    }

    // Minimum version is optional.
    if (minVersion > 0) {
        builder.appendQueryParameter("amv", Integer.toString(minVersion));
    }

    if (!TextUtils.isEmpty(androidLink)) {
        builder.appendQueryParameter("al", androidLink);
    }

    if (!TextUtils.isEmpty(playStoreAppLink)) {
        builder.appendQueryParameter("afl", playStoreAppLink);
    }

    // Return the completed deep link.
    return builder.build().toString();
}

private String generateQueryParameters() throws UnsupportedEncodingException {
    StringBuilder queryParameters = new StringBuilder();
    //server purposes
    queryParameters.append("?*code*");

    if (!customParameters.isEmpty()) {
        for (Map.Entry<String, String> parameter : customParameters.entrySet()) {
            queryParameters.append(String.format("&%1s=%2s", parameter.getKey(), parameter.getValue()));
        }
    }
    return URLEncoder.encode(queryParameters.toString(), "UTF-8");
}
Sign up to request clarification or add additional context in comments.

9 Comments

Thanks, working on the exact same thing right now as well!
How to send a retrieve those custom attributes in android?
Faris, to send those parameters i am using an sms provider, you can use whatsapp, Messenger, email, Hangouts or whatever that you want.. To retrieve the information i am using Firebase, here you can see how to add Firebase firebase.google.com/docs/android/setup Here some example code github.com/firebase/quickstart-android/tree/master/dynamiclinks This is my code (just the relevant part)
I'm facing a similar issue: stackoverflow.com/q/42093902/6144372 Please help in resolving it.
Is a set or Map with additional parameters that i need in the deeplink, generateQueryParameters is to generate basically the query string
|
0

The official answer is that you need to escape/encode a URL string so that it can be safely placed inside a URL query. I wish Firebase dynamic links would just say that about the link.

For Golang: url.QueryEscape(urlstring)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.