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.
Related
Overview
HUAWEI Image Kit's smart layout service currently offers nine different smart layout styles, and two content layout types, which users are free to choose from.
Application Scenarios
When typesetting is performed for a digital magazine, for instance, many elements need to be incorporated onto the page, along with the text. Image Kit's smart layout service enables you to typeset with remarkable ease, and craft vivid designs, to enjoy greatly enhanced efficiency with eye-catching imagery that attracts users.
{
"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"
}
Development Practice
Now, let's take a look at how to integrate Image Kit's smart layout service.
Preparations
You'll need to add your images and configure related parameters during this process.
1. Import the smart layout service packages.
Code:
import com.huawei.hms.image.vision.bean.ImageLayoutInfo ;
import com.huawei.hms.image.vision.*;
2. Obtain an instance for the smart layout service.
Code:
// Obtain an ImageVisionImpl instance.
ImageVisionImpl imageVisionAPI = ImageVision.getInstance(this);
3. Initialize the service, which is the same as that for the filter service. For details, please refer to Development Procedure.
4. Construct parameter objects.
More detail about this, please check https://forums.developer.huawei.com/forumPortal/en/topic/0204411709476790211
For details about authJson parameters, please refer to Description of authJson parameters
Example requestJson parameter configuration:
Code:
{
"requestId":"requestId",
"taskJson":{"title":"Little luxury for the new gen","description":"Away from hustle and bustle","copyRight":"HUAWEIScreenMagazine","isNeedMask":false,"anchor":"More","styleList":["info1"]}, "authJson":{"projectId":"projectIdTest","appId":"appIdTest","authApiKey":"authApiKeyTest","clientSecret":"CSecretTest","clientId":"CIdTest","token":"tokenTest"}
}
5. Obtain the service result.
When calling the smart layout API, you'll need to specify the bitmap of the image to be processed, and select the style and text to be added (parameters). For details, please refer to step 4. The smart layout service requires a network connection. If no network connection is available, the info3 style is returned by default. The layout style is returned through ImageLayoutInfo. The smart layout service draws a view based on the style contained in ImageLayoutInfo. For more detailed operations, please refer to Sample Code. Because network requests are sent over the API, you'll need to call the API in a subthread.
Code:
//Obtain the return result from ImageLayoutInfo.
new Thread(new Runnable() {
@Override
public void run() {
ImageLayoutInfo imageLayoutInfo = imageVisionAPI.analyzeImageLayout(requestJson, imageBitmap);
}
}).start();
6. Stop the service.
If you do not need to use smart layout any longer, call the imageVisionAPI.stop() API to stop the service. If the returned stopCode is 0, it means that the service has been successfully stopped.
Code:
if (null != imageVisionAPI) {
int stopCode = imageVisionAPI.stop();
}
Source Code
To download the source code, please visit GitHub.
Overview
We've grown accustomed to the hassle of connecting our devices to the Wi-Fi networks in new locations, which can be an annoyance at best, and a major frustration at worst. But perhaps more importantly, this process also comes with the risk of password leakage. Wouldn't it be nice if there was a way to connect our devices to Wi-Fi networks on an automatic basis, rather than having to manually enter the password each time?
HUAWEI Nearby Service offers a Wi-Fi sharing feature, which once integrated, equips your app to connect users on a wide range of smart devices to the Wi-Fi networks that they encounter.
Wi-FiShareDemo
Here, we've used Wi-FiShareDemo as an example, which has integrated the Wi-Fi sharing function in Nearby Service. Now, we'll show you the core code for the app, and how the app can be run.
Preparing Tools
One Huawei phone (The phone for sharing Wi-Fi must be a Huawei phone, and be connected to Wi-Fi.)
One Android device (The device to be connected to Wi-Fi must run Android 5.0 or later and have HMS Core installed, and can be a phone or a TV box.)
Android Studio (3.X or later)
Creating an app
Import the source code to Android Studio.
Register as a Huawei developer.
Create an app in Huawei AppGallery. For details, please refer to HUAWEI Developers-App Development. Note that you will need to download the agconnect-services.json file, generate the signing certificate, and save both to the app directory.
{
"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"
}
Run the app in Android Studio and install it on the test devices.
Procedures
After configuring the code and completing the installation, perform the following steps.
1.Start Wi-FiShareDemo on B, and tap Connect Wi-Fi.
2.Start Wi-FiShareDemo on A, and tap Share Wi-Fi.
3.On A, select the phone that will share Wi-Fi, make sure that the verification codes on both phones are the same, and tap ALLOW.
4.On B, tap ALLOW in the dialog box that is displayed to authorize the Wi-Fi connection.
Core Code
You can view the source code of the app in GitHub. In this app, the WifiShareHelper.java class is encapsulated based on the Nearby Service APIs. Only the APIs requestWiFiConfig and shareWiFiConfig for WifiShareHelper.java are used to connect to and share Wi-Fi.
requestWiFiConfig
// The device request to connect WiFipublic void requestWiFiConfig() { Log.d(TAG, "requestWiFiConfig"); mWifiShareEngine.startWifiShare(mWifiShareCallback, WifiSharePolicy.POLICY_SET) .addOnFailureListener(e -> Log.e(TAG, Objects.requireNonNull(e.getMessage())));}
shareWiFiConfig
// The device to share wifipublic void shareWiFiConfig() { Log.d(TAG, "Start to share WiFi"); mWifiShareEngine.startWifiShare(mWifiShareCallback, WifiSharePolicy.POLICY_SHARE) .addOnFailureListener(e -> Log.e(TAG, Objects.requireNonNull(e.getMessage()))); showListView(); setListViewListenerMode();}
Learn More
For more details, please visit HUAWEI Developers.
For further instructions, please refer to Development Guides.
To join the developer discussion, please visit Reddit.
To download the demo and sample code, please go to GitHub.
To resolve integration issues, please go to Stack Overflow.
After an app is launched, the app update function checks whether there is a later version available on AppGallery. If so, a pop-up is displayed, asking the user whether to update the app.
After you have integrated Cocos SDKHub, the function will use the SDK to check for app updates.
If your joint operations game is rejected for not integrating the app update function, check this post.
Before you integrate the app update function, you need to integrate Cocos SDKHub. (Reference: Integrating HUAWEI Game Service Based on Cocos SDKHub — Integrating Cocos SDKHub)
After that, here’s how you integrate the function:
1.Add the following code by referring to the official document:
JavaScript:
checkUpdate:function(){
var params = {
"showUpdateDialog": "1",
"forceUpdate": "0"
}
console.log("checkAppUpdate button pressed");
sdkhub.getUserPlugin().callFuncWithParam("checkAppUpdate",params);// Call the checkAppUpdate API.
}
2. Associate the code with a specified button and select the checkUpdate method as the tap event.
3. If you see the error information informing you that the callFuncWithParam method is not found during a simulator test, just test the packaged file on a real device.
{
"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"
}
4. If the following information is displayed,
the function is integrated.
XML:
D/jswrapper: JS: checkAppUpdate pressed
I/updatesdk: UpdateSDK version is: 2.0.6.302 ,flavor: envrelease ,pkgName: com.cocos2d.xxx
D/HwConnectivityServiceEx: set 10323 wlan0 value false
I/NetworkKit_a: 27569-28056|null|com.huawei.hms.framework.network.grs.a|a|22|get url from sp is not empty.
I/DeviceUtil: UpdateSDK Get url from GRS_SDK Success!https://store1.hispace.hicloud.com/hwmarket/api/
I/StoreTask: UpdateSDK call store responsecode: 200
If the function passes the real-device test, the error displayed in the simulator test may be caused by compatibility failure.
For a mobile game that needs to be forcibly updated, pay attention to:
1. Select Force update when editing information for the new game version in AppGallery Connect.
(See step 8 in the official document)
2. Set forceUpdate in the input parameters to 1.
This way, you have successfully integrated the app update function.
very useful writeup
Neha J said:
very useful writeup
Click to expand...
Click to collapse
Thank you for your liking.
Description
Recently, I converted a self-developed HTML5 app to a quick app. However, when I tried to sign in to the quick app using my Google account, error code 403 is reported, as shown in the following figure.
{
"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"
}
Analysis
The error message is “Error: disallowed_useragent”, which means that Google has imposed restrictions on the user agent of the browser loading the HTML5 app. Google also recommends using Google Chrome. So the problem must have something to do with the user agent.
Solution
1. Define a model variable, which indicates the mobile phone model of a user. Add the model variable to the data object. The sample code is as follows.
2. In the onInit() method of the page lifecycle, obtain the phone model and assign a value to model. The sample code is as follows:
JavaScript:
onInit: function () {
const device = require("@system.device")
const res = device.getInfoSync();
this.model=res.model;
3. Set the useragent attribute of the web element to Mozilla/5.0 (Linux; Android 9; {{model}}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.116 Mobile Safari/537.36)), as shown in the following figure.
Note: The model variable is used in useragent to obtain the actual phone model. This prevents users from being confused by an incorrect model obtained during the verification of useragent on some HTML5 web pages.
4. Set minPlatformVersion in the manifest.json file to 1068.
5. Load the quick app using Huawei Quick App Loader 2.2.0.304 or later. The following figure shows where to find the Quick App Loader version number.
If the sign-in still fails after the preceding steps, add the following code:
JavaScript:
multiwindow="true"
Summary
Converting an HTML5 app to a quick app is a very useful solution which allows users to use Google services (for example, Google account sign-in) on a phone without GMS.
This case can also help you resolve other sign-in problems for HTML5 quick apps.
The Huawei AppGallery Connect Crash service is a free to use crash analytics service which is supported on a wide range of platforms and frameworks.
Today lets take a look at how we can use in in a Xamarin, a hybrid framework and specifically set it up to work on iOS devices. This guide will start with a blank application but of course you can just as easily follow along and integrate into a pre-existing application!
Preparing the Xamarin Environment and Configuring Your ProjectYou need to install Visual Studio for MAC first, and then select Mobile development with .NET in Visual Studio to install the Xamarin environment.
{
"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"
}
Create a project in AppGallery Connect and enable HUAWEI Analytics.
Right-click your project and choose Manage NuGet Packages.
Find the Huawei.Agconnect.iOS.Crash package and install it.
Find the Huawei.Agconnect.iOS.AgconnectCore package, select the 1.2.0.300 version, and install it.
Add the plist file from your AppGallery Project to the project directory.
Set Build Action to BundleResource.
Developing Your AppStart by Configure the layout of your app for the testing of the crash service, in this example we will create three buttons to trigger different tests.
Double-click main.storyboard to launch Xcode, and create the MakeCrash, CatchException, and CustomReport buttons
In the MainActivity.cs file, call AGConnectCrash.Instance.TestIt to trigger a crash, call AGConnectCrash.Instance.SetUserId to set a custom user ID, call AGConnectCrash.Instance.SetCustomKey to set the key and value for a custom key-value pair, call AGConnectCrash.Instance.Log to set the log level, and call AGConnectCrash.Instance.RecordException to record a non-fatal exception.
This could look something like:
Code:
using System;
using UIKit;
using Huawei.Agconnect.Crash;
using Foundation;
namespace crashios0512
{
public partial class ViewController : UIViewController
{
public ViewController(IntPtr handle) : base(handle)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
// You can configure additional functions as required.
}
public override void DidReceiveMemoryWarning()
{
base.DidReceiveMemoryWarning();
// Delete the cached data or images that are no longer used.
}
partial void MakeCrash(UIKit.UIButton sender)
{
AGCCrash.GetSharedInstance().TestIt();
}
partial void CatchException(UIKit.UIButton sender)
{
AGCCrash.GetSharedInstance().RecordError(new Foundation.NSError());
}
partial void CustomReport(UIKit.UIButton sender)
{
AGCCrash.GetSharedInstance().SetUserId("testuser");
AGCCrash.GetSharedInstance().Log("default info level");
AGCCrash.GetSharedInstance().SetCustomValue(new NSString("test"), "this is string value");
AGCCrash.GetSharedInstance().LogWithLevel(AGCCrashLogLevel.Warning, "this is warning log level");
AGCCrash.GetSharedInstance().SetCustomValue(new NSNumber(123), "this is number");
}
}
}
View Crash ReportTap MakeCrash, CatchException, and CustomReport in sequence, and check the report in AppGallery Connect.
View the crash statistics.
Check the exceptions
Diagnose the causes of exceptions.
Check the custom key-value pairs.
View the custom log levels
View custom user IDs.
For details, please refer to:
Crash for iOS
Codelab of Crash for iOS
Will it works on offline?
will its benefit for us or not? Epoxy Flooring Atlanta