{
"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"
}
Introduction
In this article, we will learn how to integrate Huawei Analytics kit in Android application KnowMyBoard. Account Kit provides seamless login functionality to the app with large user base.
Huawei Analytics kit provides very easy and convenient way to add custom events, custom events can be used to meet personalized analysis requirements that cannot be met by automatically collected events or predefined events. Analytics Kit allows you to customize events and extend event parameters, or add personalized parameters for predefined events.
Supported Devices
Restrictions
Number of events: A maximum of 500 events are supported.
Number of event parameters: You can register a maximum of 25 parameters for each event, and a maximum of 500 event parameters for each project.
Development Overview
You need to install Android Studio IDE and I assume that you have prior knowledge of Android application development.
Hardware Requirements
A computer (desktop or laptop) running Windows 10.
Android phone (with the USB cable), which is used for debugging.
Software Requirements
Java JDK 1.8 or later.
Android Studio software or Visual Studio or Code installed.
HMS Core (APK) 4.X or later
Integration steps
Step 1. Huawei developer account and complete identity verification in Huawei developer website, refer to register Huawei ID.
Step 2. Create project in AppGallery Connect
Step 3. Adding HMS Core SDK
Let's start coding
How to Add Custom Event in AGC?
Login to AppGallery Connect Console, select projects and choose your project and navigate to Events
How to initialize Analytics Kit?
[/B]
public class MyApplication extends Application {
public static Activity myactivity;
static HiAnalyticsInstance instanceAnalytics;
@Override
public void onCreate() {
super.onCreate();
MLApplication.initialize(this);
//initialize Analytics Kit
instanceAnalytics = HiAnalytics.getInstance(this);
MLApplication.getInstance().setApiKey(Constants.API_KEY);
MapsInitializer.setApiKey(Constants.API_KEY);
}
public static HiAnalyticsInstance getAnalyticsInstance(){
return instanceAnalytics;
}
public static void setActivity(Activity activity) {
myactivity= activity;
}
public static Activity getActivity() {
return myactivity;
}
}
[B]
How to send Custom Events?
[/B][/B]
private void sendEvent(String eventName,String eventType) {
Bundle bundle = new Bundle();
bundle.putString(eventType,eventType);
bundle.putString( "event_time", getTime());
MyApplication.getAnalyticsInstance().onEvent(eventName, bundle);
}
[B][B]
Result
Tricks and Tips
Makes sure that agconnect-services.json file added.
Make sure required dependencies are added
Make sure that service is enabled in AGC
Enable data binding in gradle.build file
Enable debug mode to see events details in get App debugging hit this command in terminal
adb shell setprop debug.huawei.hms.analytics.app pkg_name
Conclusion
Finally, we have learnt how to integrate Huawei Analytics kit in Android application KnowMyBoard. You can check the desired result in the result section. You can also go through previous article part-5 here. Hoping Huawei Analytics kit capabilities are helpful to you as well, like this sample, you can make use as per your requirement.
Thank you so much for reading. I hope this article helps you to understand the integration of Huawei Analytics kit in Android application KnowMyBoard.
Reference
Huawei Analytics Kit — Training video
Checkout in forum
Related
HUAWEI Analytics Kit is based on the event analytics data model.
The analytics data model uses the Event-Param-User model to record data, describes events using parameters, and describes the characteristics of 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"
}
HUAWEI Analytics Kit collects the AAID that is allocated by the HMS Instance ID to each app instance installed on the device. The AAID is used for connecting various HMS Core services, such as HUAWEI Push Kit, HUAWEI Analytics Kit, and Remote Configuration.
The AAID will be reset in the following scenarios:
The user uninstalls or reinstalls the app.
The user restores the device to its factory settings.
The user clears the app data.
The app calls the clearCachedData API.
Procedure
1. Initialize the HMS Core Analytics SDK by calling the getInstance API.
Code:
HiAnalyticsInstance instance = HiAnalytics.getInstance(context);
2. Record defined events using the onEvent API. For definitions of the events, please refer to Event Description.
3. Call APIs of HUAWEI Analytics Kit to implement the corresponding functions. For details, please refer to API Reference. For example, call the setUserProfile API to set user attributes.
Sample Code
1. After the agconnect-services.json file is imported successfully, initialize HUAWEI Analytics Kit in the onCreate method of the first activity to obtain a HiAnalyticsInstance instance. If the agconnect-services.json file is incorrect, data cannot be collected at specified trigger points.
Code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Enable SDK log recording.
HiAnalyticsTools.enableLog();
HiAnalyticsInstance instance = HiAnalytics.getInstance(this);
// Or use the context for initialization.
// Context context = this.getApplicationContext();
// HiAnalyticsInstance instance = HiAnalytics.getInstance(context);
// instance.setUserProfile("userKey","value");
}
2. Insert trigger points in proper positions of the code.
Code:
//Customize trigger points and add trigger points in the proper position of the code.
Bundle bundle = new Bundle();
bundle.putString("exam_difficulty","high");
bundle.putString("exam_level","1-1");
bundle.putString("exam_time","20190520-08");
instance.onEvent("begin_examination", bundle);
//Add trigger points for predefined events.
Bundle bundle_pre = new Bundle();
bundle_pre.putString(PRODUCTID, "item_ID");
bundle_pre.putString(PRODUCTNAME, "name");
bundle_pre.putString(CATEGORY, "category");
bundle_pre.putLong(QUANTITY, 100L);
bundle_pre.putDouble(PRICE, 10.01);
bundle_pre.putDouble(REVENUE, 10);
bundle_pre.putString(CURRNAME, "currency");
bundle_pre.putString(PLACEID, "location_ID");
instance.onEvent(ADDPRODUCT2WISHLIST, bundle_pre);
Using the Debug Mode
During the development, you can enable the debug mode to view the event records in real time, observe the results, and adjust the event tracing scheme.
Enabling/Disabling the Debug Mode
Run the following command on an Android device to enable the debug mode:
Code:
adb shell setprop debug.huawei.hms.analytics.app package_name
After the debug mode is enabled, all events will be reported in real time.
Run the following command to disable the debug mode:
Code:
adb shell setprop debug.huawei.hms.analytics.app .none.
You can go to HUAWEI Analytics > Management > App Debugging to view the reported data, as shown in the following figure.
For details about how to view the analysis data, please refer to App Debugging.
In this article, we’ll learn how to use DTM in our Flutter projects.
{
"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"
}
Flutter is a free and open-source mobile UI framework. It allows you to create a native mobile application with only one codebase. This means that you can use one programming language and one codebase to create two different apps for iOS and Android. In this case, we’ll integrate the Dynamic Tag Manager (DTM) into a Flutter project. With Dynamic Tag Manager, you can dynamically update tracking tags on a web-based UI to track specific events and report data to third-party analytics platforms, tracking your marketing activity data as needed.
Configure your project on AppGallery Connect
Registering a Huawei ID
You need to register a Huawei ID to use the plugin. If you don’t have one, follow the instructions here.
Preparations for Integrating HUAWEI HMS Core
First of all, you need to integrate Huawei Mobile Services with your application. I will not get into details about how to integrate your application but you can use this tutorial as step by step guide.
Configuring the AndroidManifest.xml File
Code:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Process
1. Enabling Flutter Analytics Plugin
In Flutter you are advised to integrate HUAWEI Analytics Kit for recording custom events. The Flutter Analytics Plugin enables communication between HUAWEI Analytics SDK and Flutter platform. This plugin exposes all functionality provided by HUAWEI Analytics SDK. Let’s start by integrating Flutter Analytics Plugin to our pubspec.yaml file. There are two ways to do this. For both ways, after running pub get command, the plugin is ready to use.
Code:
dev_dependencies:
flutter_test:
sdk: flutter
huawei_analytics:
path: hms/huawei_analytics
Code:
dev_dependencies:
flutter_test:
sdk: flutter
huawei_analytics: ^4.0.4
2. Operations on the Server
To access the DTM portal, perform the following steps: On the Project Setting page, go to Growing > Dynamic Tag Manager.
Click Create configuration on the DTM portal and set Configuration name, App type, Operation record, and Tracked data.
View the configuration on the Configuration management page. You can click its name to access the configuration page.
The configuration is a general term for all resources in DTM, including Overview, Variable, Condition, Tag, Group, Version, and Visual Event.
On the Overview tab page, you can view the change history and operation records of variables, conditions, and tags in the current configuration version.
A variable is a placeholder used in a condition or tag. DTM provides preset variables which can be used to configure most tags and conditions. You can also create your own custom variables.
Creating a Preset Variable
Creating a Custom Variable
Condition
A condition is the prerequisite for triggering a tag and determines when the tag is executed. A tag must contain at least one trigger condition.
Creating a Condition
Tag
A tag is used in your app to track events. DTM supports the HUAWEI Analytics and custom function templates, as well as many third-party tag extension templates. With DTM, you do not need to add additional third-party tracking tags in your app.
Creating a Tag
Create and Release a Version
Downloading a Version
Importing a Configuration File
3. Configuring the Code
Code:
import 'package:huawei_analytics/analytics.dart';
Code:
class _MyHomePageState extends State<MyHomePage> {
final HMSAnalytics hmsAnalytics = new HMSAnalytics();
Future<void> _onCustomEvent(BuildContext context) async {
String name = "Purchase";
dynamic value = {'price': 90};
await hmsAnalytics.onEvent(
name, value);
}
Code:
floatingActionButton: FloatingActionButton(
onPressed:(){
_onCustomEvent(context);
},
),
Results:
Through the Verification process, we successfully integrated Dynamic Tag Manager into Flutter project.
For more information about HUAWEI Dynamic Tag Manager (DTM), visit
https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/introduction-0000001050043907
Related Links
Original post: https://medium.com/huawei-developers/using-dynamic-tag-manager-dtm-in-flutter-project-f052d24731e4
Nice and useful article
Why do we need to add dependecies for huawei analytics ? what is the integration relationship between Analytics and DTM?
useful sharing, thanks!!
Introduction
{
"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"
}
Quality improvement has become crucial in this era of digitalization where all our documents are kept in the folders, shared over the network and read on the digital device.
Imaging the grapple of an elderly person who has no way to read and understand an old prescribed medical document which has gone blurred and deteriorated.
Can we evade such issues??
NO!!
Let’s unbind what Huawei ML Kit offers to overcome such challenges of our day to day life.
Huawei ML Kit provides Text Recognition API to improvise the quality and visibility of old and blurred text on an image.
Text Recognition API is very important and useful the industries where the data is huge and required to be extracted from the images.
Text Recognition API provides two ways to read and process the data on an image:
Local
Huawei ML kit’s Text Recognition API can detect and read the text on an image using the algorithms configured on the device itself and does not require any interaction with cloud and internet.
Remote
Huawei ML kit’s Text Recognition API can analyse and read the text on an image using cloud algorithm API and require interaction with cloud and internet.
Development Overview
We will be focusing on simple text recognition from an image using on device detection API’s
Prerequisite
1. Must have a Huawei Developer Account
2. Must have a Huawei phone with HMS 4.0.0.300 or later
3. React Native environment with Android Studio, Node Js and Visual Studio code.
Major Dependencies
1. React Native CLI : 2.0.1
2. Gradle Version: 6.0.1
3. Gradle Plugin Version: 4.0.1
4. React Native ML Kit SDK : 5.0.0
5. react-native-hms-ml kit gradle dependency
6. AGCP gradle dependency
Software Requirements
1. Java SDK 1.8 or later
2. Android 5.0 or later
Preparation
1. Create a react native project using React Native CLI and open android directory.
2. Download the React Native ML Kit SDK and paste it under Node modules directory of React Native project.
3. Create an app and project in the Huawei AppGallery Connect.
4. Provide the SHA Key and App Package name of the project.
5. Enable the ML API and download the agconnect-services.json file and paste to the app folder of your android folder.
Integration
Add below to build.gradle (project) file, under buildscript/repositories and allprojects/repositories.
Code:
Maven {url 'http://developer.huawei.com/repo/'}
Add below to build.gradle (app) file, under dependencies to use the ML kit SDK in your React Native application.
Code:
dependencies{
// Import the SDK.
implementation project(":react-native-hms-ml ")
…
…
implementation 'com.huawei.agconnect:agconnect-core:1.2.1.301'
}
Add below under Settings.Gradle file
Code:
include ':react-native-hms-ml
project(':react-native-hms-ml).projectDir = new File(rootProject.projectDir, '../node_modules/react-native-hms-ml /android')
Add below under MainApplication,java file.
Code:
import com.huawei.hms.rn.ml.HmsMlPackage;
public class MainApplication extends Application implements ReactApplication {
...
@Override
protected List<ReactPackage> getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
//Add following line. Don't forget to add import statement also.
packages.add(new HmsMlPackage());
return packages;
}
...
};
Use case
Huawei ML kit’s Text Recognition API provides many different use cases, however our focus would be reading a hand written note and display the text on the application using on device capabilities of the API.
App.js
App.js file acts as entry point and creates navigation to navigate on required service page.
More details, you can check https://forums.developer.huawei.com/forumPortal/en/topic/0204424693794850035
Interesting.
Rebis said:
Interesting.
Click to expand...
Click to collapse
THANKS
If the text is not visible properly using this service can we extract the data.
{
"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"
}
These days mobile devices are part of our life. We do many operations from our mobile phones such as making payment, logging in to social media accounts, checking our bank accounts.
These are the operations which need high security level. If our device will have malicious apps or something like that, our accounts will have trouble and we may suffer many financial and moral damages.
In this article, I will talk about how to improve app security by using HMS Safety Detect Kit.
To do that, I have developed a simple secure web browser app. Because in web browsers, we can use bank websites, we can login to our social media, we can make some payment and use our credit/bank card information. We wouldn’t like to our information to be stolen.
Code:
def koinVersion = "2.2.0-rc-4"
dependencies {
....
// Koin for Android
implementation "org.koin:koin-android:$koinVersion"
// Koin Android Scope feature
implementation "org.koin:koin-android-scope:$koinVersion"
// Koin Android ViewModel feature
implementation "org.koin:koin-android-viewmodel:$koinVersion"
}
After we have implemented the Koin dependencies, we need to create our modules which we will add in our application class.
We will get necessary objects with the help of these modules. I prefer to define different module files for different works.
Code:
val applicationModule = module {
single(named("appContext")){ androidApplication().applicationContext }
factory { HmsHelper() }
factory { SystemHelper() }
}
Code:
val dataModule = module {
factory<ErrorItem>(named("HmsNotAvailable")) { ErrorItem(
icon = ContextCompat.getDrawable(get(named("appContext")), R.drawable.huawei)!!,
title = androidContext().getString(R.string.hms_not_available),
message = androidContext().getString(R.string.download_hms_core)) }
factory<ErrorItem>(named("DeviceNotSecure")) { ErrorItem(
icon = ContextCompat.getDrawable(get(named("appContext")), R.drawable.ic_device_not_secure)!!,
title = androidContext().getString(R.string.device_not_secure),
message = androidContext().getString(R.string.device_not_secure_message)) }
factory<ErrorItem>(named("MaliciousApps")) { ErrorItem(
icon = ContextCompat.getDrawable(get(named("appContext")), R.drawable.ic_malicious_apps)!!,
title = androidContext().getString(R.string.device_not_secure),
message = androidContext().getString(R.string.malicious_apps_message)) }
}
App Preparations
I use Koin framework for dependency injection in my application.
To use Koin Framework in our application, we should add 3 dependencies to our app. In the above, you can find dependencies which you need to add in app-level build.gradle file.
Code:
val viewModelModule = module {
viewModel { SplashViewModel() }
}
After we have defined our modules, we need to setup Koin in our application class.
While starting Koin, we should add our modules which we have defined above, and if we want to use app context, we should androidContext value.
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.berkberber.hms_securewebbrowser">
....
<application
android:name=".SecureWebBrowserApp"
....
>
....
</application>
</manifest>
Code:
class SecureWebBrowserApp: Application(){
override fun onCreate() {
super.onCreate()
setup()
}
private fun setupKoin(){
startKoin {
androidContext([email protected])
modules(
applicationModule,
viewModelModule,
dataModule
)
}
}
private fun setup(){
setupKoin()
}
}
To get more information about app and to see how I used other things such as Navigation Component, MVVM, and etc. you can visit my GitHub repository.
HMS Safety Detect
Safety Detect Kit helps us to improve the security level of our apps. There are 5 different APIs we can use with HMS Safety Detect Kit.
SysIntegrity API: Helps us to check device security. We can determine that device has been rooted or has not.
AppsCheck API: Helps us to determine and list malicious apps which have installed to device.
URLCheck API: Helps us check whether websites are safe.
UserDetect API: Helps us to determine that user is fake or is not.
WifiDetect API: Helps us to check whether Wi-Fi which the device has connected is secure.
Note: UserDetect API is available outside of Chinese mainland. WifiDetect API is available only in the Chinese mainland.
In this article, I have been focused on app security. So, I used SysIntegrity API and AppsCheck API and I will give you informations about these APIs.
Checking is HMS available on device (optional)
We will use Safety Detect Kit in our application. Safety Detect Kit requires HMS Core to be installed on the device.
We don’t have to make this control, but if device doesn’t have HMS, we can’t use HMS Safety Detect Kit. That’s why I recommend you to check HMS Core availability on device and if device doesn’t have HMS, it is better to show an error screen to user.
To check HMS availability we need to add base HMS dependency to our app-level build.gradle file.
To check that device has HMS support or has not, we can write very basic function called as isHmsAvailable().
More details, you can check https://forums.developer.huawei.com/forumPortal/en/topic/0204429014247900019
Introduction
Push notifications offers a great way to increase your application’s user engagement and boost your retention rates by sending meaningful messages or by informing users about your application. These messages can be sent at any time and even if your app is not running at that time. To achieve this you need to follow steps.
Huawei Push Kit is a messaging service developed by Huawei for developers to send messages to apps on users’ device in real time. Push Kit supports two types of messages: notification messages and data messages, which we will cover both in this tutorial. You can send notifications and data messages to your users from your server using the Push Kit APIs or directly from the AppGallery Push Kit Console.
Things required
1. Unity Engine must be installed in the system.
2. Huawei phone or cloud debugging.
3. Visual Studio 2019
4. Android SDK & NDK
Steps to integrate
1. Sign In and Create or Choose a project on AppGallery Connect portal.
{
"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. Navigate to Project settings and download the configuration file.
3. Enable Push Kit from Manage APIs section.
4. Click Agree the Push service Agreement.
5. Select Data storage location.
6. Click Enable now Push notification.
7. Send Notification from the console.
8. Enter all the required details and click on Submit.
Game Development
1. Create a new game in Unity.
2. Now add game components and let us start game development.
3. Download HMS Unity Plugin from below site.
https://github.com/EvilMindDevs/hms-unity-plugin/releases
4. Open Unity Engine and import the downloaded HMS Plugin.
Choose Assets > Import Package> Custom Package
5. Choose Huawei > App Gallery.
6. Provide the AppId and other details from agconnect-service.json file and click configure Manifest.
7. Create Huawei Push Kit based scripts.
C#:
using UnityEngine;
namespace HuaweiHms{
public class IPushServiceListener:AndroidJavaProxy{
public IPushServiceListener():base("com.unity.hms.push.IPushService"){}
public virtual void onMessageReceived(RemoteMessage arg0) {
}
public void onMessageReceived(AndroidJavaObject arg0) {
onMessageReceived(HmsUtil.GetHmsBase<RemoteMessage>(arg0));
}
public virtual void onMessageSent(string arg0) {
}
public virtual void onNewToken(string arg0) {
}
public virtual void onSendError(string arg0, BaseException arg1) {
}
public void onSendError(string arg0, AndroidJavaObject arg1) {
onSendError(arg0,HmsUtil.GetHmsBase<BaseException>(arg1));
}
public virtual void onTokenError(BaseException arg0) {
}
public void onTokenError(AndroidJavaObject arg0) {
onTokenError(HmsUtil.GetHmsBase<BaseException>(arg0));
}
}
}
Result
Tips and Tricks
1. HMS plugin v1.2.0.
2. Make sure that you have installed HMS Core.
3. The Push Kit server allows a maximum of 1,000 tokens for sending messages at a time.
4. If exceed more than 1k it need to be sent batch wise.
Conclusion
In this article, we have learnt what is push service, how to integrate in Unity based game. And also we have learnt that how to send notification from Huawei console to device.
References
Unity Push kit