Ads Kit offers Publisher Service for developers, helping them obtain high-quality ads by resource integration, based on a vast Huawei device user base; it also provides Identifier Service for advertisers to deliver personalized ads and attribute conversions.
Now, let's share some problems that developers often encounter when integrating the kit for your reference.
1. What can I do if the banner ad dimensions zoom in when the device screen orientation is switched from portrait to landscape?
{
"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"
}
Solution:
Fix the width or height of BannerView. For example, the height of the banner ad is fixed in the following code:
Code:
<com.huawei.hms.ads.banner.BannerView
android:id="@+id/hw_banner_view"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
The following figure shows how a banner ad is normally displayed.
2. How to request more than one native ads at a time?
You can call loadAds() to request multiple native ads.
A request initiated by loadAds() should contain two parameters: AdParam and maxAdsNum. The maxAdsNum parameter specifies the maximum number (that is, 5) of ads to be loaded. The number of returned ads will be less than or equal to that requested, and the returned ones are all different. Sample code is as follows:
Code:
nativeAdLoader.loadAds(new AdParam.Builder().build(), 5);
After ads are successfully loaded, the SDK calls the onNativeAdLoaded() method of NativeAd.NativeAdLoadedListener multiple times to return a NativeAd object each time. After all the ads are returned, the SDK calls the onAdLoaded() method of AdListener to send a request success notification. If no ad is loaded, the SDK calls the onAdFailed() method of AdListener.
In the sample code below, testy63txaom86 is a test ad unit ID, which should be replaced with a formal one before app release.
Code:
NativeAdLoader.Builder builder = new NativeAdLoader.Builder(this, "testy63txaom86");
NativeAdLoader nativeAdLoader = builder.setNativeAdLoadedListener(new NativeAd.NativeAdLoadedListener() {
@Override
public void onNativeAdLoaded(NativeAd nativeAd) {
// Called each time an ad is successfully loaded.
...
}
}).setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
// Called when all the ads are successfully returned.
...
}
@Override
public void onAdFailed(int errorCode) {
// Called when all ads fail to be loaded.
...
}
}).build();
nativeAdLoader.loadAds(new AdParam.Builder().build(), 5);
Note: Before reusing NativeAdLoader to load ads, ensure that the previous request is complete.
3. What can I do if "onMediaError : -1" is reported when a roll ad is played in rolling mode in an app?
After the roll ad is played for the first time, the error code -1 is returned when the roll ad is played again.
Cause analysis:
1. The network is unavailable.
2. The roll ad is not released after the playback is complete. As a result, the error code -1 is returned during next playback.
Solution:
1. Check the network. To allow apps to use cleartext HTTP and HTTPS traffic on devices with targetSdkVersion 28 or later, configure the following information in the AndroidManifest.xml file:
Code:
<application
...
android:usesCleartextTraffic="true"
>
...
</application>
2. Release the roll ad in onMediaCompletion() of InstreamMediaStateListener. The roll ad needs to be released each time playback is complete.
Code:
public void onMediaCompletion(int playTime) {
updateCountDown(playTime);
removeInstream();
playVideo();
}
private void removeInstream() {
if (null != instreamView) {
instreamView.onClose();
instreamView.destroy();
instreamContainer.removeView(instreamView);
instreamContainer.setVisibility(View.GONE);
instreamAds.clear();
}
}
To learn more, please visit:
>> Ads Kit
>> Development Guide of Ads Kit
Related
Overview
The Image Vision service provides you with 24 color filters, which are easy to use.
Use Cases
An app needs to beautify or retouch images.
Development Procedure
The Image Vision service renders the images you provide and returns them to your app.
1. Import the Image Vision service packages.
Code:
import com.huawei.hms.image.vision.*;
import com.huawei.hms.image.vision.bean.ImageVisionResult;
2. Construct an ImageVision instance. The instance will be used to perform related operations such as obtaining the filter effect.
Code:
// Obtain an ImageVisionImpl instance.
ImageVisionImpl imageVisionAPI = ImageVision.getInstance(this);
3 Initialize the service. To call setVisionCallBack during service initialization, your app must implement the ImageVision.VisionCallBack API with its onSuccess(int successCode) and onFailure(int errorCode) methods rewritten. If the ImageVision instance is successfully obtained, the onSuccess method is called and then the Image Vision service is initialized. If the ImageVision instance fails to be obtained, the onFailure method is called and an error code is returned. Your app is allowed to use the Image Vision service only after the successful verification. That is, the value of initCode must be 0, indicating that the initialization is successful.
Code:
imageVisionAPI.setVisionCallBack(new ImageVision.VisionCallBack() {
@Override
public void onSuccess(int successCode) {
int initCode = imageVisionAPI.init(context, authJson);
...
}
@Override
public void onFailure(int errorCode) {
...
}
});
Description of authJson parameters:
{
"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"
}
You can find the preceding parameters except token in the agconnect-services.json file.
4. Construct a jsonObject object.
Description of requestJson and imageBitmap parameters:
Description of requestJson parameters:
Description of taskJson parameters:
For details, see the description of authJson parameters in step 3.
filterType mapping:
5. Obtain the rendered image.
When calling the getColorFilter() API, you need to specify the bitmap image to be rendered and select the required filter. In addition, you need to pass the authentication information. Your app can use the service only after it is successfully authenticated. On receiving the request from your app, the filter service parses the image and returns the rendered view to the app.
Note: Call the API in a subthread other than the main thread. If the image cannot be displayed during the test, it is recommended your turn off hardware acceleration.
Code:
//Obtain the rendering result from visionResult.
ImageVisionResult visionResult = imageVisionAPI.getColorFilter(requestJson,imageBitmap);
Description of visionResult parameters:
Description of responseJson parameters:
To turn off hardware acceleration, configure the AndroidManifest.xml file as follows:
Code:
<application
...
android:hardwareAccelerated="false"
...
</application>
6. Stop the Image Vision service.
If you do not need to use filters any longer, call the imageVisionAPI.stop() API to stop the Image Vision service. If the returned stopCode is 0, the service is successfully stopped.
Code:
if (null != imageVisionAPI) {
int stopCode = imageVisionAPI.stop();
}
Hi,
am facing an issue while integrated image vision API
2020-10-08 18:21:49.971 3143-3143/com.huawei.sujith.imageeditor E/ImageVisionImpl: ClassNotFoundException: Didn't find class "com.huawei.hms.image.visionkit.dynamic.FunctionCreator" on path: DexPathList[[zip file "/data/user_de/152/com.huawei.android.hsf/modules/external/huawei_module_imagevision/10003301/com.huawei.hms.image.visionkit-10003301.apk"],nativeLibraryDirectories=[/data/user_de/152/com.huawei.android.hsf/modules/external/huawei_module_imagevision/10003301/com.huawei.hms.image.visionkit-10003301.apk!/lib/arm64-v8a, /system/lib64, /hw_product/lib64, /system/product/lib64]]
More information like this, you can visit HUAWEI Developer Forum
Introduction
This article shows the setp to integrate HMS Flutter Location plugin with a news app.
The news app will obtain the country that the user is located in. It will then fetch that country's news headlines and display them onto a list.
For example, if the user is currently located in Hong Kong, the app will show Hong Kong's news headlines on launch. The user may switch to read other countries' news headlines afterwards.
{
"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"
}
The datasource of the news headlines are obtained from the NewsAPI.
Configuration
Assuming that there is already a running Flutter app,
*Update: for 1) and 2), the plugin is now uploaded to pub.dev, there is no need to download and configure it manually.
Add this to your pubspec.yaml is the preferred way.
Code:
dependencies:
huawei_location: ^4.0.4+300
1) Download the huawei_location flutter plugin and unzip it. For this project, it is placed under the project's root.
2) Configure pubspec.yaml to add the following under dependencies. Replace the path to your own's.
Code:
huawei_location:
path: 'hms/location/huawei_location'
3) Configure AndroidManifest.xml for location permission.
Code:
<uses-permission android:name="android.permission.ACCESS_COARES_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
Project Structure
The architecture of the flutter project is shown below, which is adapted from this repo.
https://github.com/FilledStacks/flutter-tutorials/tree/master/010-provider-architecture
The project is layered into three parts, namely UI, Services and Business Logic.
The UI is dumb and display only what it is given. It will not contain any logic to process the data.
The Service provides various services and exposes APIs for others to use.
The business logic contains view models and models etc.
Since the UI is pretty simple and does not contain any logic to process data, we will mainly focus on Services and Business Logic.
Services
1) Permission Service
Accessing user's location generally requires permission at runtime.
The permission services expose two methods to achieve this. For convenience, the built-in PermissionHandler from Huawei-location plugin is used.
Code:
class PermissionServicesImpl implements PermissionServices {
PermissionHandler _permissionHandler = PermissionHandler();
@override
Future<bool> hasLocationPermission() async {
return _permissionHandler.hasLocationPermission();
}
@override
Future<bool> requestLocationPermission() async {
return _permissionHandler
.requestLocationPermission();
}
}
For this app, the permission to obtain user's location information is acquired during app launch. If the user has allowed, the country code obtained is saved with SharedPreferences.
Code:
Future<void> _initApp() async {
final isPermitted = await _permissionServices.requestLocationPermission();
if(isPermitted == null) {
await _sharedPreferencesServices.saveCountryCode(CommonString.defaultCountry);}
if(isPermitted) {
final hwLocation = await _locationService.getHWLocation();
if(hwLocation != null) {
await _sharedPreferencesServices.saveCountryCode(hwLocation.countryCode);
}
} else {
await _sharedPreferencesServices.saveCountryCode(CommonString.defaultCountry);
}
}
2) Location Service
The location service provides only one method to return HWLocation using huawei_location plugin.
It utilizes location plugin's FusedLocationProviderClient.getLastLocationWithAddress(LocationRequest) to acquire HWLocation.
Remember to set LocationRequest.needAddress to true if you need to obtain the address information also.
Code:
class LocationServicesImpl implements LocationService {
final PermissionServices _permissionServices =
serviceLocator<PermissionServices>();
@override
Future<HWLocation> getHWLocation() async {
if (await _permissionServices.hasLocationPermission()) {
FusedLocationProviderClient locationService =
FusedLocationProviderClient();
LocationRequest locationRequest = LocationRequest();
locationRequest.needAddress = true;
final hwLocation = locationService
.getLastLocationWithAddress(locationRequest);
return hwLocation;
}
}
}
3) SharedPreferences Service
The shared preferences service allows the ability to store and retreive country code. For simplicity, only the abstract class is shown.
Code:
abstract class SharedPreferencesServices {
Future<void> saveCountryCode(String countryCode);
Future<String> getCountryCode();
}
4) TopHeadlines Service
TopHeadlines service allows the ability to fetch a specific countries' news headlines and also to change to another countries' news headlines. For simplicity, only the abstract class is shown.
Code:
abstract class TopHeadlinesService {
Future<List<Article>> getTopHeadlines(String countryCode);
Future<List<Article>> changeHeadlinesLanguage(String countryCode);
}
Business Logic
1) HeadlinesScreenViewModel:
This viewmodel is responsible for managing the state of the headlines screen, processing data and gluing all parts together.
In case of a change in state, the viewmodel will notify its listneres (the UI), so that they could act on the event.
To complete the picture, in the loadData method, the country code is first retreived from SharedPreferences, the country code is then used to call getTopHeadlines(String countryCode) to fetch the headline news of that particular country.
The app will call loadData at the initState lifecycle method of the headlines screen.
Code:
void loadData() async {
_setIsLoading(true);
final _countryCode = await _sharedPreferencesServices
.getCountryCode()
.timeout(Duration(milliseconds: 2000), onTimeout: () => CommonString.defaultCountry);
_headlines = await _topHeadlinesService
.getTopHeadlines(_countryCode)
.timeout(Duration(milliseconds: 2000), onTimeout: () => null);
_setIsLoading(false);
}
The above explains the necessary parts of using HMS Location kit for Flutter.
If you are interested in the details, feel free to visit the github repo.
https://github.com/lkhe/news_app
Introduction
HUAWEI Image Kit provides smart image editing, designing and animating capabilities into your application. It provides Image Vision service for 24 unique colour filters, 9 smart layouts as well as the image theme tagging, text arts, image cropping and many more functionalities. It also provide Image rendering service for five basic animations and nine advance animations capabilities.
It provides two SDKs, Image Vision SDK and Image Render SDK.
Image Vision service APIs to implement functions such as filter, smart layout, sticker, theme tagging and image cropping.
Image Render service APIs to implement basic and advanced animation effects.
Software Requirements
Java JDK 1.8 or later
Android API Level 26 or higher
EMUI 8.1 or later (applicable to the SDK, but not the fallback-SDK)
HMS Core (APK) 4.0.2.300 or later (applicable to the SDK, but not the fallback-SDK)
Functions
Basic Animations
Advanced Animations
Image Editing
Integration Preparations
To integrate HUAWEI Image Kit, you must complete the following preparations:
Register as a developer.
Create an Android Studio project.
Generate a signing certificate fingerprint.
Configure the signing certificate fingerprint on AG Console.
Integration steps
In this article we are going to implement filter service, although Image Vision provides five major functionalities which is most commonly used by image editing application and many more.
First, we need to add the Image Vision SDK dependencies in app build.gradle file.
Code:
dependencies {
...
implementation 'com.huawei.hms:image-vision:1.0.3.301'
implementation 'com.huawei.hms:image-vision-fallback:1.0.3.301'
...
}
Note: Image Kit works only on a device running Android 8.0 or later.
For initializing the service. call setVisionCallBack during service initialization, your app must implement the ImageVision. VisionCallBack API and override its onSuccess(int successCode) and onFailure(int errorCode) methods.
Code:
ImageVisionImpl imageVisionAPI = ImageVision.getInstance(this);
imageVisionAPI.setVisionCallBack(new ImageVision.VisionCallBack() {
@Override
public void onSuccess(int successCode) {
int initCode = imageVisionAPI.init(context, authJson);
...
}
@Override
public void onFailure(int errorCode) {
...
}
});
After Initializing the service select the Image from gallery :
Code:
public static void getByAlbum(Activity act) {
Intent getAlbum = new Intent(Intent.ACTION_GET_CONTENT);
String[] mimeTypes = {"image/jpeg", "image/png", "image/webp"};
getAlbum.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
getAlbum.setType("image/*");
getAlbum.addCategory(Intent.CATEGORY_OPENABLE);
act.startActivityForResult(getAlbum, 801);
}
Note: The image size should not be greater than 15 MB, resolution should not be greater than 8000 x 8000 pixel and the aspect should be in between 1:3 to 3:1.
There are 24 different colour filters provided by Filter Service. For each type of filter we have separate respective mapping code. Image Vision will return a bitmap filtered by one of these 24 colour filters.
{
"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"
}
Make sure that we call the getColorFilter() API in the background thread. For calling the filter API, you need to specify the bitmap of the image to be processed and the filter effect and set the filtered image on imageView.
Code:
//Obtain the rendering result from visionResult.
new Thread(new Runnable() {
@Override
public void run() {
ImageVisionResult visionResult = imageVisionAPI.getColorFilter(requestJson,imageBitmap);
}
}).start();
After getting the filtered result, If you do not want to use filters any longer, call the imageVisionAPI.stop() API to stop the Image Vision service. If the returned stopCode is 0, the service is successfully stopped.
Code:
if (null != imageVisionFilterAPI) {
int stopCode = imageVisionFilterAPI.stop();
}
More details, you can check https://forums.developer.huawei.com/forumPortal/en/topic/0203429680523150041
{
"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"
}
AppGalleryKit App and AppGalleryKit Game services allows to jointly operate the apps with Huawei and share revenue generated in the process. Developer will have access to Huawei’s diverse services including HUAWEI AppGallery connection, data reports, activity operations, and user operations to obtain more premium HUAWEI AppGallery resources in order to promotion purposes.
To enable AppGalleryKit App or AppGalleryKitGame operations, you need to sign the HUAWEI AppGallery Connect Distribution Service Agreement For Paid Apps with Huawei. For details about the joint operations process, please refer to Joint Operations Services at a Glance.
AppGalleryKit App and AppGalleryKit Game is a product concept derived from Account, Analytics, In-App Purchases and other kits. With AppGalleryKit App or AppGalleryKit Game, initializing the app, updating the app, implementing Account Kit is optional. But it is necessary to implementing In-App Purchases kit to use AppGalleryKit App or AppGalleryKit Game. Also it is advised that use Analytics Kit, Auth Service, Crash Service, A/B Testing and APM.
AppGalleryKitApp or AppGalleryKitGame is not pure kit integration. It is required for developers to sign AppGalleryKitApp or AppGalleryKitGame related agreements and they are derived from many features.
Initiliazing app, updating the app, Account Kit and In-App Purchases can be implemented seperately. These kits do not depend on AppGalleryKitApp or AppGalleryKitGame. But AppGalleryKitApp or AppGalleryKitGame depends on these kits.
Although we are not going to use AppGalleryKitApp or AppGalleryKit game, we can still use the update status of the application. In this article, we will check if there is an update in a demo app. Of course due to this app will not be in AppGallery market, there will not any update required.
In order to use this feature, first HMS Core is needed to be integrated to the project.
You can click this link to integrate HMS Core to your project.
Adding Dependency
After HMS Core is integrated, app-service library needs to be implemented.
Code:
implementation 'com.huawei.hms:appservice:{version}' // Currently version is 5.0.4.302
We will create a checkUpdate method and use it in onCreate. JosApps.getAppUpdateClient method, AppUpdateClient instance will be obtained. This object provides the methods related to app update. checkAppUpdate method, checks for app updates after the app is launched and initialized.
Java:
private void checkUpdate(){
AppUpdateClient client = JosApps.getAppUpdateClient(this);
client.checkAppUpdate(this, new UpdateCallBack(this));
}
We need to create a static class which is UpdateCallBack and it will implement CheckUpdateCallBack. CheckUpdateCallBack returns a result for checking for app updates. It requires onUpdateInfo, onMarketInstallInfo, onMarketStoreError and onUpdateStoreError methods are implemented.
in onUpdateInfo method, we can get status code, fail code, fail reason and other informations.
For more information you can click this link.
Code:
private static class UpdateCallBack implements CheckUpdateCallBack {
private final WeakReference<MainActivity> weakMainActivity;
private UpdateCallBack(MainActivity mainActivity) {
this.weakMainActivity = new WeakReference<>(mainActivity);
}
public void onUpdateInfo(Intent intent) {
if (intent != null) {
MainActivity mainActivity = null;
if (weakMainActivity.get() != null){
mainActivity = weakMainActivity.get();
}
int status = intent.getIntExtra(UpdateKey.STATUS, 100);
int rtnCode = intent.getIntExtra(UpdateKey.FAIL_CODE, 200);
String rtnMessage = intent.getStringExtra(UpdateKey.FAIL_REASON);
Serializable info = intent.getSerializableExtra(UpdateKey.INFO);
if (info instanceof ApkUpgradeInfo && mainActivity != null ) {
AppUpdateClient client = JosApps.getAppUpdateClient(mainActivity);
//Force Update option is selected as false.
client.showUpdateDialog(mainActivity, (ApkUpgradeInfo) info, false);
Log.i("AppGalleryKit", "checkUpdatePop success");
}
if(mainActivity != null) {
//status --> 3: constant value NO_UPGRADE_INFO, indicating that no update is available.
Log.i("AppGalleryKit","onUpdateInfo status: " + status + ", rtnCode: "
+ rtnCode + ", rtnMessage: " + rtnMessage);
}
}
}
@Override
public void onMarketInstallInfo(Intent intent) {
//onMarketInstallInfo
}
@Override
public void onMarketStoreError(int i) {
//onMarketStoreError
}
@Override
public void onUpdateStoreError(int i) {
//onUpdateStoreError
}
}
In this example, due to we do not have the application released in the market, we got a status code which is equal to 3. This indicates that for the application there is no upgrade needed.
For all status codes, you can check the below image.
For more details, you can check AppGalleryKit App and AppGalleryKit Game development guide links in reference section. Also you can download this demo application from the Github link.
Reference
AppGalleryKit App
AppGalleryKit Game
Github
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