[Huawei Developers] Mayism:
Background​

App Linking provides services across diverse platforms, but its services differ depending on the Android channel.

If you read through App Linking documentation, you’ll discover that all app stores such as Google Play and HUAWEI AppGallery will be launched for a user if your app has not been installed on the user’s Android device. Then the user can select one from which to install the app.

Cause​

When a local app store is started, the app package name is queried to locate the app details page. However, the app package name varies depending on the channel. For example, for a Huawei channel, the package name ends with .huawei, which is different from that in a Google channel.

Does this mean it’s impossible for an App Linking link to be opened in all local app stores due to package name inconsistency? The answer is no because there is a solution to this problem.

Solution:​

Perform the following to resolve the issue:

We know that App Linking can redirect users to a custom website if the app has not been installed, so you can use Android intents to create custom links, in which you can configure the package name and fallback URL to be opened. The basic syntax is as follows:

intent:
HOST/URI-path // Optional host
#Intent;
package=[string];
action=[string];
category=[string];
component=[string];
scheme=[string];
S.browser_fallback_url=[encoded_full_url]
end;

Taking advantage of the preceding functions, you can:

1. Create a link of App Linking and use the setOpenType(CustomUrl) method to set the open type to redirect users to a custom website for the Android platform. The involved APIs are as follows:

.setAndroidLinkInfo(new AppLinking.AndroidLinkInfo.Builder()
.setAndroidDeepLink(Android_LINK)
.setOpenType(CustomUrl)
.setFallbackUrl(BACK_LINK)
.build())

2. Use an Android intent to configure the preceding custom website. Here, I use Taobao as an example:

"intent://details?id=com.taobao.taobao#Intent;scheme=appmarket;package=com.huawei.appmarket;S.browser_fallback_url=https://play.google.com/store/apps/details?id=com.taobao.taobao;end"

The process is as follows:

1. Use the appmarket scheme to start the app whose package name is com.huawei.appmarket, that is, to open HUAWEI AppGallery.

2. Pass the package name com.taobao.taobao to HUAWEI AppGallery. Then, HUAWEI AppGallery will start this package.

3. If com.huawei.appmarket is not found, set S.browser_fallback_url to a fallback URL.

4. The fallback URL is a Google Play link. Simply set id in this URL to the name of the package to be opened. In this example, the ID is com.taobao.taobao.

Practice and Test​

Ensure that an App Linking project of the Android platform has been completed. For details, visit this site.

Open the original App Linking project and add the following information in bold:

String BACK_LINK = "intent://details?id=com.taobao.taobao#Intent;" +
"scheme=appmarket;package=com.huawei.appmarket;" +
"S.browser_fallback_url=https://play.google.com/store/apps/details?" +
"id=com.taobao.taobao;end";
AppLinking.Builder builder = new AppLinking.Builder()
.setUriPrefix(DOMAIN_URI_PREFIX)
.setDeepLink(Uri.parse(DEEP_LINK))
.setAndroidLinkInfo(new AppLinking.AndroidLinkInfo.Builder()
.setAndroidDeepLink(Android_DEEP_LINK)
.setOpenType(CustomUrl)
.setFallbackUrl(BACK_LINK)
.build());

Test:

1. Install the demo on a device, create a link of App Linking, and add it to the note.

2. Uninstall the app to simulate the scenario where the app is not installed.

3. For a Huawei phone, tap Open/Download. On AppGallery that is displayed, open the Taobao details page. The following figure shows the Taobao details page in HUAWEI Browser.

4. For a non-Huawei phone, tap Open/Download. On Google Play that is displayed, open the Taobao details page. The following figure shows the Taobao details page in Google Chrome.

5. The problem is now resolved. If you encounter a similar problem, simply follow my example step by step and change the package name to resolve the issue.

For more details, please go to:

https://developer.huawei.com/consum...ry-connect-Guides/agc-applinking-introduction