java – How to open an app when navigating to an Android link

Question:

For example, the site has special links aliexpress://product/desc?productId=32309744542 when aliexpress://product/desc?productId=32309744542 on which the AliExpress application opens. If I need to add a GET parameter, for example, aliexpress://?param=32309744542 it must be passed to the link, like this: http://m.aliexpress.com?param=32309744542 (in a normal browser). The link cannot be viewed in the app so I want to know if this will work?

Answer:

On android, the scheme is as follows:

  1. In the manifest for the desired IntentFilter , an IntentFilter added, in which it is indicated which links are clicked on to respond.
  2. In this activity, already in the code through the Intent a link is pulled out with which the application is launched. The link is parsed into parts and the logic of its processing is built.

In the manifest something like this (first there is an example of regular links to a site, then something like the one you wrote in the question):

<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="site.org"
        android:pathPrefix="/something"
        android:scheme="http" />
    <data
        android:host="*.site.org"
        android:scheme="http" />
    <data
        android:host="www.site.org"
        android:pathPrefix="/something"
        android:scheme="http" />
   <data
        android:scheme="aliexpress" />
</intent-filter>

In the activity, we get the link like this:

Uri data = getIntent().getData();
Log.d("ЛОГ", "Uri data: " + data);
Scroll to Top