How get extra parameter from dynamic link using Firebase?

Bryan Acuña Núñez picture Bryan Acuña Núñez · Jul 7, 2016 · Viewed 12.1k times · Source

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: "https:// airbanq.send.com/sendmoney" without the addiotional parameters

i am using this sample code https://github.com/firebase/quickstart-android/tree/master/dynamiclinks

any help please,

Thanks

My code

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();
}

Answer

Bryan Acu&#241;a N&#250;&#241;ez picture Bryan Acuña Núñez · Jul 7, 2016

Thats was my solution

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");
}