BackgroundApp 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.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
CauseWhen 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:
XML:
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:
Java:
.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:
XML:
"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 TestEnsure 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:
Java:
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
Related
Publish your Applications: Huawei AppGallery
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Huawei AppGallery is a distribution platform for introducing your application to end users on your Huawei mobile device, providing ability to search, download and share your applications.
AppGallery focuses on below major features to ensure applications uploaded on the platform are safe to use and download.
1. Four-layer Threat Detection
2. Smart and Exclusive App Selection
3. Exclusive Gift Packs
4. Diverse App Rankings
5. Smart Search
6. Quick Manager
Create and Upload your Application
Below needs to be followed in order to proceed with application upload.
Sign Up or Sign In
Create an account by signing-up to AppGallery. One can use their mobile no. or email Id to register as a developer.
Creating and Publishing a new application
Once your developer account is created, redirect to upload your app link, under “distribute” page.
Now re-direct to next page as shown below and select “My apps”
Once “My apps” been clicked, it will re-direct to the application page where new application needs to be created.
Select “New app” tab here and add parameters as below to create a new application.
Package Type: Application can have apk or rpk (quick app).
Category: Choose category for an application or game.
Language: Choose suitable language among 78 supported languages.
Once all the parameters are filled, click on “ok”.
Now under “Distribute” page, add “App information” as below
And click on “save”
Once “save” is clicked, click on “ok”.
After confirming the operation, application will re-direct under “Draft” page. Add release information here.
1> Add country and regions information as below
2> Scroll down and add packages or upload APK file as below by clicking on “software packages”
Tip: Please turn off proxy/svn while uploading a new apk/package.
3> Add other information as required.
Payment info: Payment info is added as free or through merchant account.
· In-app purchase: If your application is using the in-app purchase sdk, please provide this information.
· Content Rating: This is required to apply appropriate age for your application.
· Privacy policy: This is required to ensure the safe feature of application.
· Copyright Information: Provided to upload any important document or image.
· Review Information: Provide a test account and password in case we need to use some of your app functions that require user authentication, such as sign-in, in-app content viewing, and in-app purchases. The account will be used by our reviewer to verify these functions.
· Release schedule: Select a date on which app should be released in the app gallery.
Once all the release details are filled. Click on “save”.
Now, click on “Ok”.
Once application is saved, click on “Submit” and “Confirm” in the nect step.
Once application is submitted to AppGallery, same will be sent for review shown below.
Cheers!!
You can view your application in AppGallery under “MyApps” as below.
Reference: https://developer.huawei.com/consumer/en/doc/30204#h2-2-1-publishing-a-new-app
Conclusion
We can now publish our application with ease.
Background
A developer team wants to integrate HUAWEI Out-of-App Purchases, allowing users to purchase a product on the app details page of a game on HUAWEI AppGallery. To use this mode, they need to deep link a user to the app details page, and pass the ID of the product for purchase..
Official documentation: https://developer.huawei.com/consumer/en/doc/development/AppGallery-connect-Guides/appgallerykit-devguide-game#h1-1589804284330
Let’s see how they achieved this.
Implementation
1. Activity Configuration in the Manifest File
The team added intent-filters for an activity of their game.
<data android:scheme=”agpms” androidath=”/product/pay” android:host=”com.sxx.huawei”/>
The assembled request URL is agpms://com.sxx.huawei/product/pay.
The official documentation describes the requirements on the link.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Sample code:
2. Code Implementation of Redirection (Opening a Deep Link from Another App)
HUAWEI AppGallery should be used for the testing. However, the team had not released the game on AppGallery, and they failed to find a test environment on the AppGallery side. So they turned to another app.
Java:
Intent intent = new Intent();
intent.setAction("com.google.open02");
intent.addCategory("android.intent.category.DEFAULT");
intent.setData(Uri.parse("agpms://com.sxx.huawei/product/pay?producid=TestProduct503"));
startActivity(intent);
agpms://com.sxx.huawei/product/pay?producid=TestProduct503
Generally, the parameter following a question mark (?) is in the format of key=value&key1=value1.
Sample code:
As shown in the sample code, the only parameter set is producid.
3. Parameter Parsing After Redirection to the Payment Page
If the details page has not been opened before the redirection, the onCreate method of the app activity needs to be called to obtain the intent object for data parsing.
If the details page has already been opened before the redirection, the onNewIntent method of the app activity needs to be called to obtain the intent object for data parsing.
Sample code:
After the team obtains the product ID from the parsed data, the HMS Core SDK displays the payment page.
FAQs
What should I do if I fail to open the payment page after configuring the deep link?
Generally, this problem is caused by the inconsistency between scheme, host, and path in the assembled URL and those in the configuration. You can perform a check by referring to the official documentation.
These posts have shown the first few steps of developing a Unity-based game:
Unity Editor Installation and APK Packaging: https://forums.developer.huawei.com/forumPortal/en/topic/0204435788744370088?fid=0101187876626530001
How Can I Use the HUAWEI Game Service Demo Provided by Unity:
So far, you are able to run a game demo provided by Unity.
This post can help you further test the demo to see whether it can:
Complete some of the initialization operations.
Support HUAWEI ID sign-in and obtain player information.
After the demo test, you can write your own code by referring to the demo.
APIs provided by Unity:
APIs for game initialization:
Huawei GameService.AppInit()
HuaweiGameService.Init()
APIs for game sign-in:
HuaweiGameService.Login(ILoginListener listener)
HuaweiGameService.SilentSignIn(ILoginListener listener)
HuaweiGameService.SignOut(ILoginListener listener)
HuaweiGameService.CancelAuthorization(ICancelAuthListener listener)
APIs for obtaining player information:
HuaweiGameService.GetCurrentPlayer(bool isRealTime, IGetPlayerListener listener)
For details about these APIs, see the official documentation of Unity:
https://docs.unity.cn/cn/Packages-cn/[email protected]/manual/appgallery.html#7-api-references-list
Sign-in Process
According to Huawei’s restrictions on joint operations games (https://developer.huawei.com/consum...ry-connect-Guides/appgallerykit-devguide-game), if your game will be:
Released in the Chinese mainland, call the following APIs:
AppInit > Init > login > getCurrentPlayer
Released outside the Chinese mainland only, the following APIs are optional:
AppInit > Init > login > getCurrentPlayer
HUAWEI ID sign-in is also optional.
In this example, I was going to release an app in the Chinese mainland, so I called the related APIs.
Demo Test
Test environment requirements
Device: A Huawei phone running EMUI 10.0.0, with Android 10
HMS Core (APK) version: 5.0.4.301
HUAWEI AppGallery version: 11.0.2.302
Unity version: 2020.1.2f1c1
You can obtain the demo code by referring to the following file. When an API is called, Unity displays a message indicating the calling result, which is very convenient for you to locate faults.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Test steps
1. Start the demo. The following page is displayed.
By default, the HuaweiGameService.AppInit() API is called during app launch. The preceding message indicates that the API is successfully called.
2. Click Init. The following information is displayed.
Note: For a joint operations game, this API needs to be called when the game is launched, as required by Huawei. Unity’s demo provides a button for you to call the API.
3. Click Login, then login. The HUAWEI ID sign-in page is displayed.
Click Authorise and log in. A greeting banner and logs are displayed, indicating that the sign-in is successful.
Note: Ensure that the greeting banner is displayed, or your joint operations game may be rejected during app review.
4. Click getCurrentPlayer. The following information indicates that the player information API is called successfully.
For details about how to verify the player information, please check the official documentation:
https://developer.huawei.com/consumer/en/doc/development/HMS-References/verify-login-signature
The game sign-in is complete when the player information is approved.
Other optional APIs:
HuaweiGameService.SilentSignIn(ILoginListener listener)
Click silentSignIn. The following information indicates that the API is called successfully.
HuaweiGameService.SignOut(ILoginListener listener)
Click signOut. The following information is displayed.
HuaweiGameService.CancelAuthorization(ICancelAuthListener listener)
Click cancelAuthorization. The following information is displayed.
Click login again. The sign-in page is launched again, indicating that the authorization is canceled.
Relevant LogsYou may encounter a failure to create object types when integrating Cloud DB. Typical logs are as follows:
1. The ObjectType quantity is invalid.
XML:
NaturalBase: GenerateDiffSchemas: remove ObjectType is not supported. count of ObjectType is less than current
2. The object types failed to be negotiated.
XML:
E/NaturalBase: OpenNaturalStore: negotiate failed.
W/AGConnectCloudDB: openCloudDBZone: failed to create or open a cloudDBZone.
3. The scheme is not synchronized.
XML:
[NaturalCloudSyncModule][OnConnected]: negotiate schema.
[PushMessageAndNotifyStoreCv] Schema is UnSynced
4. The version of object types been changed but object types themselves are not changed.
XML:
E/NaturalBase: CreateObjectType: ObjectType version has changed, but ObjectType has not changed.
E/AGConnectCloudDB: createObjectType: failed to create ObjectType into the AGCConnectCloudDB.
Cause AnalysisThe main cause is that the file matching the object type version in your Android project is inconsistent with the object types set on the AppGallery Connect server.
You can check the object types in AppGallery Connect as follows.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
To check information relevant to object types in your Android project, check the class in ObjectTypeInfoHelper.
Three Steps to Solve the Problem1. Exporting Object Types from AppGallery ConnectSince the object types in your Android project are inconsistent with those in AppGallery Connect, you need to export the object types from AppGallery Connect for synchronization.
The export procedure in AppGallery Connect is as follows: Sign in to AppGallery Connect, click My projects, click your project, go to Build > Cloud DB > ObjectTypes, select the specific version, and click Export.
During the export, select JAVA for the file format and android for the file type of Java, and enter a package name.
Decompress the exported ZIP package in your project directory.
2. Checking VersionsYou should pay attention to two versions in the object type file, which correspond to the following two fields in the ObjectTypeInfoHelper file:
1. FORMAT_VERSION: The value should match the SDK version.
If the value of FORMAT_VERSION in the exported file is 1, integrate the Cloud DB SDK of a version earlier than 1.2.2. Version 1.2.1.301 is recommended.
If the value of FORMAT_VERSION in the exported file is 2, integrate the Cloud DB SDK of a later version. Version 1.2.3.301 is recommended.
2. OBJECT_TYPE_VERSION
This version is that selected when you export object type information from AppGallery Connect. Generally, you do not need to change it.
3. Uninstalling Your App from Your Device and Installing It AgainIf you have encountered the object type problem on your device, the incorrect information will still exist in the cache if you install your app again directly, and object type creation will still fail.
The correct method for performing the app re-installation is as follows:
1. Package your app again.
2. Uninstall the app already installed on your device manually.
3. Install the newly packaged app on your device for debugging.
The correct method for performing the app re-installation is as follows:
https://developer.huawei.com/consum...ect-Guides/agc-clouddb-agcconsole-objecttypes
Previously, I've introduced how to quickly report app events to Google Analytics using DTM without releasing app updates. Now, the visual event tracking requirement has changed to report events to Firebase for multi-dimensional data analysis. The following uses a case to explain the process of reporting events to Firebase using DTM.
Case:
Report the $AddProduct2Cart event to Firebase using DTM.
Procedure:
1. Preparations
Before modifying the DTM configuration, ensure that you have completed the following preparations:
a. The DTM SDK has been integrated into the app.
b. The Firebase SDK has been integrated into the app.
c. The $AddProduct2Cart event has been configured for the app using the Analytics SDK.
Code:
Bundle bundle = new Bundle();
bundle.putString(PRODUCTID, "xxx");
bundle.putString(PRODUCTNAME, "xxx");
HiAnalytics.getInstance(context).onEvent(HAEventType.ADDPRODUCT2CART, bundle);
</p>
2. Modifying the DTM Configuration.
2.1 Creating a Variable
Go to Grow > Dynamic Tag Manager > Variable. Click Configure, select Event Name, and click OK.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
2.2 Creating a Tag.
On the Tag page, click Create to create a Firebase tag. Configure the tag as follows:
Name: Enter a custom tag name.
Extension: Select Google Analytics (Firebase).
Event name: This parameter is optional. Select the check box and enter the renamed event name AddProduct2Cart (events reported to Firebase cannot contain the dollar sign $).
Parameters for addition: Set Key to price and Value to 1000.
Set Trigger condition to the created condition.
3. Creating and Releasing a Version.
Create and release a new configuration version on the Version page. The app with the DTM SDK integrated will periodically check and download the latest configuration version and report events according to this version.
In the Create version dialog box, select Create and release version.
4. Viewing the Reported Event on Firebase.
After completing the preceding operations, you can view the reported event on Firebase.
By default, the DTM SDK checks and downloads the latest configuration version at an interval of 6 hours. To download the latest configuration version immediately, clear the app cache and restart the app. DTM will not report events immediately if the debug mode is not enabled. Instead, events are reported every 10 minutes when the app is running. To report events immediately, run the following ADB commands:
Code:
adb shell setprop debug.huawei.hms.dtm.app <package_name>
adb shell setprop debug.firebase.analytics.app <package_name>
There may be a delay of several minutes for Firebase to receive the renamed event AddProduct2Cart triggered in the app.
Go to Analytics > DebugView to view the latest reported events.
The reported event name is AddProduct2Cart. The event has the price parameter and the parameter value is 1000, which is consistent with that set in DTM. This means that the DTM configuration has taken effect.
To learn more, please visit:
Our official website
Our development documentation page to find the documents you need
Reddit to join our developer discussion
GitHub or Gitee to download the demo and sample code
Stack Overflow to solve any integration problems
Original Source