2

I don't have public web URLs which I can annotate to support App Links, so I use Facebook's Mobile Hosting API for App Links.

According to the app links doc, I can pass the canonical URL ( https: //fb.me/xxxxxxxxxx ) provided by the App Links Hosting API. The canonical URL includes three information, URL、APP Name、Package Name, and the URL is like this:

    my_app_scheme://actions?ads_name=1

I try to get the QueryParameter("ads_name") of URL from Android Data to open defined page of app. I use the following code.

    AppLinkData.createFromActivity(MainActivity.this);
    if (AppLinks.getTargetUrl(intentOtherApp) != null) {
       Uri targetUrl = AppLinks.getTargetUrl(intentOtherApp);
           if (targetUrl != null) {

            Bundle appLinkData = AppLinks.getAppLinkData(getIntent());
            if (appLinkData != null) {
                String targetURLString = appLinkData.getString("target_url");
                Uri targetURL = Uri.parse(targetURLString);
                JSONObject jsonObject = new JSONObject();

                String adsName = targetURL.getQueryParameter("ads_name");

                try {
                    if (adsName != null) {
                        jsonObject.put("ads_name", adsName);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
            */
        }
    }

But I cannot get the data, I always get only the canonical URL. How can I pass my query data from Facebook apps link? And does the app be installed or not be installed using the same method?

Neo Hsiung
  • 51
  • 1
  • 4

1 Answers1

1

The target_url is always the URL that's shared, in your case, it's https: //fb.me/xxxxxxxxxx

If you want the query params, you have two choices:

  1. add the query param to your canonical url when you share it (e.g. https: //fb.me/xxxxxxxxxx?ads_name=1)
  2. instead of getting the target_url, just use the url from the incoming intent's data field (e.g. Uri uri = getIntent().getData(), this will be the custom url, or my_app_scheme://actions?ads_name=1)
Ming Li
  • 15,672
  • 3
  • 37
  • 35
  • I tried the option 1. It' s useful for a installed app. I can get the query param which I want. But it still can not work on a uninstalled app device. When I use facebook ad to redirect user to goole play and install my app, it didn't pass any query param. – Neo Hsiung Aug 19 '15 at 02:50
  • I also try the option 2. I get the null uri from the intent. I use the [App Links Hosting API generator](https://developers.facebook.com/quickstarts/?platform=app-links-host) which is provided by Facebook. According to the facebook doc, it will pass my url, but it didn't. Do you have any idea? Thanks a lot for your reply. – Neo Hsiung Aug 19 '15 at 02:57
  • What is the URL that you created? I can have a look. – Ming Li Sep 01 '15 at 17:10
  • Also, for your install use case, if you're using the mobile app install ads product from Facebook, you can call AppLinkData.fetchDeferredAppLinkData() when your app starts, and it will fetch the app link that was used to install your app. – Ming Li Sep 01 '15 at 17:11
  • Hello @MingLi I have also the same question and i have already asked on SO , What i need to pass in share dialog ? how to create App links ? Facebook documentation for mobile app hosting is not containing proper information – Harsh Trivedi Jul 31 '17 at 11:00