Integrating HUAWEI Share Kit into Huawei Phone Apps in Two Easy Steps - Huawei Developers

More information, you can visit HUAWEI Developer Forum.​
Huawei Share capabilities are open to all apps. They can be seamlessly embedded into the sharing logic of apps that integrate HUAWEI Share Kit, creating a consistent UI for sharing across app. Apps can open the Huawei Share page using the Intent method and call the Huawei Share APIs. For details, see the Huawei Share to Become Available in Apps.
Read on to find out how to quickly integrate HUAWEI Share Kit into phone apps.
Step 1: Configuring files
Because the demo runs on a Huawei phone which has integrated Huawei Share, it does not need to integrate the Share Kit SDK.
1. Configure the build.gradle file for your app:
Code:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.aar'])
implementation 'com.android.support:support-compat:28.0.0'
}
2. Change the minSdkVersion value in the file to 26.
{
"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"
}
3. Click the sync button to synchronize the project.
Step 2: Integrating and developing functions
1. Share text content.
Code:
private void doStartTextIntent() {
String text = shareText.getText().toString();
if (TextUtils.isEmpty(text)) {
return;
}
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType(SHARE_INTENT_TYPE);
intent.putExtra(Intent.EXTRA_TEXT, "test text");
intent.setPackage(SHARE_PKG);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PackageManager manager = getApplicationContext().getPackageManager();
List<ResolveInfo> infos = manager.queryIntentActivities(intent, 0);
if (infos.size() > 0) {
// size == 0 indicates that the current device does not support Intent-based sharing.
getApplicationContext().startActivity(intent);
}
}
2. Share files.
Code:
private void doStartFileIntent() {
String text = shareText.getText().toString();
if (TextUtils.isEmpty(text)) {
return;
}
ArrayList<Uri> uris = getFileUris(text);
if (uris.isEmpty()) {
return;
}
Intent intent;
if (uris.size() == 1) {
// Shares one file.
intent = new Intent(Intent.ACTION_SEND);
intent.setType(SHARE_INTENT_TYPE);
intent.putExtra(Intent.EXTRA_STREAM, uris.get(0));
intent.setPackage(SHARE_PKG);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
} else {
// Shares multiple files.
intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.setType(SHARE_INTENT_TYPE);
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
intent.setPackage(SHARE_PKG);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
PackageManager manager = getApplicationContext().getPackageManager();
List<ResolveInfo> infos = manager.queryIntentActivities(intent, 0);
if (infos.size() > 0) {
// size == 0 indicates that the current device does not support Intent-based sharing.
getApplicationContext().startActivity(intent);
}
}
HUAWEI Share Kit is now integrated. But before you get started, make sure you have the following:
· Two Huawei phones running EMUI 9.0 or later for debugging, one which can be used as the sender, and the other which can be used as the receiver
· Java JDK (1.8 or later).
· Android API (level 26 or higher).
· Android Studio development environment: V3.0.1 or later is recommended
For more information about integrating HUAWEI Share Kit into Huawei phone apps, see the Preparations for Integrating HUAWEI Share Kit into Huawei Phone Apps.
For more information about HUAWEI Share Kit, visit HUAWEI Developers.
Recommended reading:
Share Kit | Fully-Open HUAWEI Linux Share Kit Unveiled, Allowing for File Transfers Between Huawei and Linux Devices
Fully-Open HUAWEI Windows Share Kit Unveiled, Offering a New Paradigm for Phone-PC File Transfers

Related

Great way to test android apps[HMS and GMS], A/B Testing

More information about this, you can visit HUAWEI Developer Forum
​Introduction
This article will guide you to use A/B testing in android project. It will provide details to use HMS and GMS.
Steps
1. Create App in Android
2. Configure App in AGC
3. Integrate the SDK in our new Android project
4. Integrate the dependencies
5. Sync project
Procedure
Step1: Create application in android studio.
HMS related dependencies, Add below dependencies in app directory
Code:
implementation 'com.huawei.agconnect:agconnect-remoteconfig:1.3.1.300'
apply plugin:'com.huawei.agconnect'
Add below dependencies in root directory
Code:
maven { url 'http://developer.huawei.com/repo/' }
classpath 'com.huawei.agconnect:agcp:1.2.1.301'
GMS related dependencies, Add below dependencies in app directory
Code:
implementation 'com.google.android.gms:play-services-analytics:17.0.0'
implementation 'com.google.firebase:firebase-config:19.2.0'
Add below dependencies into root directory
Code:
classpath 'com.google.gms:google-services:4.3.3'
Step2: Create MobileCheckService class, using this class you can identify whether the device has HMS or GMS.
Code:
class MobileCheckService {
fun isGMSAvailable(context: Context?): Boolean {
if (null != context) {
val result: Int = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context)
if (com.google.android.gms.common.ConnectionResult.SUCCESS === result) {
return true
}
}
return false
}
fun isHMSAvailable(context: Context?): Boolean {
if (null != context) {
val result: Int = HuaweiApiAvailability.getInstance().isHuaweiMobileServicesAvailable(context)
if (com.huawei.hms.api.ConnectionResult.SUCCESS == result) {
return true
}
}
return false
}
}
Step3: Create instance for Mobilecheckservice inside activity class. Inside OnCreate() call checkAvailableMobileService().This method return whether the device has HMS or GMS.
Code:
private fun checkAvailableMobileService() {
if (mCheckService.isHMSAvailable(this)) {
Toast.makeText(baseContext, "HMS Mobile", Toast.LENGTH_LONG).show()
configHmsTest()
} else
if (mCheckService.isGMSAvailable(this)) {
Toast.makeText(baseContext, "GMS Mobile", Toast.LENGTH_LONG).show()
configGmsTest()
} else {
Toast.makeText(baseContext, "NO Service", Toast.LENGTH_LONG).show()
}
}
Step4: If the device support HMS, then use AGConnectConfig.
Code:
private fun configHmsTest() {
val config = AGConnectConfig.getInstance()
config.applyDefault(R.xml.remote_config_defaults)
config.clearAll()
config.fetch().addOnSuccessListener { configValues ->
config.apply(configValues)
config.mergedAll
var sampleTest = config.getValueAsString("Festive_coupon")
Toast.makeText(baseContext, sampleTest, Toast.LENGTH_LONG).show()
}.addOnFailureListener { Toast.makeText(baseContext, "Fetch Fail", Toast.LENGTH_LONG).show() }
}
Step5: If the device support GMS, then use FirebaseRemoteConfig.
Code:
private fun configGmsTest() {
val firebase = FirebaseRemoteConfig.getInstance();
val configSettings = FirebaseRemoteConfigSettings.Builder().build()
firebase.setConfigSettingsAsync(configSettings)
firebase.setDefaultsAsync(R.xml.remote_config_defaults)
firebase.fetch().addOnCompleteListener { configValues ->
if (configValues.isSuccessful) {
firebase.fetchAndActivate()
var name = firebase.getString("Festive_coupon")
Toast.makeText(baseContext, name, Toast.LENGTH_LONG).show()
} else {
Toast.makeText(baseContext, "Failed", Toast.LENGTH_LONG).show()
}
}
}
App Configuration in Firebase:
Note: A/B test is using HMS configuration, refer
https://forums.developer.huawei.com/forumPortal/en/topicview?tid=0201248355275100167&fid=0101187876626530001
Step1: To configure app into firebase Open firebase https://console.firebase.google.com/u/0/?pli=1
{
"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"
}
Step2: Click Add Project and add required information like App Name, package name, SHA-1.
Step3: After configuration is successful, then click A/B Testing in Grow menu.
To Start A/b testing experiment Click Create experiment button, It will show you list of supported experiments. Using Firebase you can do three experiments.
· Notifications
· Remote Config
· In-App Messaging
Notification: This experiment will use for sending messages to engage the right users at the right moment.
Remote Config: This experiment will use to change app-behavior dynamically and also using server-side configuration parameters.
In-App Messaging: This experiment will use to send different In-App Messages.
Step4: Choose AbTesting > Remote Config > Create a Remote Config experiment, provide the required information to test, as follows
Step5: Choose AbTesting > Remote Config > App_Behaviour, following page will display.
Step6: Click Start experiment, then start A/B test based on the experiment conditions it will trigger
Step7: After successful completion of experiment, we can get report.
Conclusion:
Using A/B test, you can control the entire experiment from HMS or GMS dashboard, this form of testing will be highly effective for the developers.
Reference:
To know more about firebase console, follow the URL https://firebase.google.com/docs/ab-testing
Share your thoughts on this article, if you are already worked with A/B tests, then you can share your experience on separation between them with us

Integrate Unity & Account Kit

Unity & HMS account kit integration.
In this article, we will integrate HMS account kit with Unity. We will perform Login & Logout.
Requirements ->
Unity Editor
Huawei device
Visual Studio
Output --> Upon succeful login User will get display name and other details, On UI i am populating DisplayName like below.
{
"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"
}
Step 1 Create Unity 3d project
Step 2 Register project on HMS Console as Game.
(Dont forget to put SHA key from keystore file)
Step 3 Collect below information
Step 4 Download HMS Unity Plugin (HMS Unity Plugin v1.1.2) from
Code:
https://github.com/EvilMindDevs/hms-unity-plugin/releases
Step 5 Import this plugin in Unity project like show below
Step 6 Additoinal Configuration using HMS Plugin, click on Huawei -> App Gallery
Step 7
in step 3 we collected information which we need to fill here in Huawei Plugin Editor, like show below
Step 8 Once information is filled a button will appear "Configure Manifest", click on that and close editor
Step 9 Verify details in manifest file, you can find this file in below location
Assets -> Plugins -> Android -> AndroidManifest.xml
We need to verify above filled details in this file like show below
Step 10 Update & Verify package name like below
File -> BuildSettings -> Android -> Player Settings -> Other Settings
Step 11 Install Unity Remote apk in your huawei device for running and debugging project
Please use custom keystore
Build the project and try to run -> if it gives error like manifest merger failed, which i got, open manifest file in text editor and fix it, if it has duplicate providers, once done you can see ur project running in huawei device
Step 12 HMS Plugin apis will be available as soon as prefab is added to the scene like below
Where to find prefab -> Assets -> Huawei -> Prefabs
Step 13 Scripting
I am going to create 2 scripts, both are conncted on my Player (U can connect on any element)
PlayerController - I used this to initalize HMS Account Kit
UpdateDetails - to update user name on canvas received from HMS account service.
PlayerController.cs
Code:
using System.Collections;
using System.Collections.Generic;
using HmsPlugin;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float runSpeed;
Rigidbody myRb;
Animator myAnim;
bool facingRight;
private AccountManager accountManager;
UpdateDetails updateDetails;
// Start is called before the first frame update
void Start()
{
updateDetails = GetComponent<UpdateDetails>();
myRb = GetComponent<Rigidbody>();
myAnim = GetComponent<Animator>();
facingRight = true;
accountManager = AccountManager.GetInstance(); // Initialization of account manager
accountManager.OnSignInSuccess = OnLoginSuccess;
accountManager.OnSignInFailed = OnLoginFailure;
Debug.LogWarning("kamal Start");
accountManager.SignIn(); // login
}
public void OnLoginSuccess(HuaweiMobileServices.Id.AuthHuaweiId authHuaweiId)
{
//loggedInUser.text = string.Format(LOGGED_IN, authHuaweiId.DisplayName);
Debug.LogWarning("kamal OnLoginSuccess-->"+ authHuaweiId.DisplayName);
updateDetails.updateUserName("Welcome "+authHuaweiId.DisplayName);
}
public void OnLoginFailure(HuaweiMobileServices.Utils.HMSException error)
{
//loggedInUser.text = LOGIN_ERROR;
Debug.LogWarning("kamal OnLoginSuccess");
updateDetails.updateUserName("error in login-- " + error.Message);
}
// Update is called once per frame
void Update()
{
}
}
UpdateDetails.cs -> update details on UI Canvas
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UpdateDetails : MonoBehaviour
{
public Text userName;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void updateUserName(string name) {
Debug.LogWarning("kamal updateUserName-->" + name);
userName.text = name;
}
}
Result -> User name is shown on UI after login using HMS account kit.
What about Logout -> User below code snipped
Code:
accountManager.SignOut();
Nice article
I am not able to retreive email id of user once successful login, it gives me null. what might be the reason

Make Users to Update Your Application with HMS

{
"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

Intermediate: How to Integrate Huawei Dark-Mode and App Status awareness into flutter Application

Introduction
In this article, we will learn how to implement Huawei Awareness kit features, so we can easily integrate these features in to our Flutter application. In this article we are going to take a look at the Awareness kit Capture API features such as Dark mode awareness and App status awareness.
{
"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"
}
What is Huawei Awareness kit Service?
Huawei Awareness kit supports to get the app insight into a users’ current situation more efficiently, making it possible to deliver a smarter, more considerate user experience and it provides the users’ current time, location, behavior, audio device status, ambient light, weather, and nearby beacons, application status, and mobile theme mode.
Restrictions
1. Dark mode: It supports EMUI 10.0 or later for Huawei devices and non-Huawei devices required Android 10.0 or later (API level 29 is required).
2. App status: It supports EMUI 5.0 or later for Huawei devices and non-Huawei devices currently it is not supporting
Requirements
1. Any operating system(i.e. MacOS, Linux and Windows)
2. Any IDE with Flutter SDK installed (i.e. IntelliJ, Android Studio and VsCode etc.)
3. Minimum API Level 29 is required.
4. Required EMUI 10.0 For Dark-mode and EMUI 5.0 for App status.
How to integrate HMS Dependencies.
1. First of all, we need to create an app on AppGallery Connect and add related details about HMS Core to our project. For more information check this link
2. Enable the Awareness Kit in the Manage API section and add the plugin.
3. Add the required dependencies to the build.gradle file under root folder.
Code:
maven {url 'http://developer.huawei.com/repo/'}
classpath 'com.huawei.agconnect:agcp:1.4.1.300'
4. Now we can implement Awareness Kit plugin. To implement Awareness Kit to our app, we need to download the plugin. Follow the URL for cross-platform plugins.
5. After completing all the above steps, you need to add the required kits’ Flutter plugins as dependencies to pubspec.yaml file. You can find all the plugins in pub.dev with the latest versions.
Code:
huawei_awareness:
path: ../huawei_awareness/
After adding them, run flutter pub get command. Now all the plugins are ready to use.
Note: Set multiDexEnabled to true in the android/app directory, so the app will not crash.
Use Awareness to get the dark mode status
With Dark-mode Status Awareness, we can detect the dark mode status of the device. We can get the status using capture API.
Code:
void loadAppTheme() async {
DarkModeResponse response = await AwarenessCaptureClient.getDarkModeStatus();
bool isDarkMode = response.isDarkModeOn;
setState(() {
if (isDarkMode) {
Provider.of<ThemeChanger>(context).setTheme(darkTheme);
} else {
Provider.of<ThemeChanger>(context).setTheme(lightTheme);
}
});
}
Use Awareness to get the Application status
With Application status Awareness, we can detect whether application is in which mode like silent, running using package name.
Code:
void checkAppStatus() async {
String packName = "******************";
ApplicationResponse response =
await AwarenessCaptureClient.getApplicationStatus(
packageName: packName);
int appState = response.applicationStatus;
setState(() {
switch (appState) {
case ApplicationStatus.Unknown:
_showDialog(context, "Demo Application Not found");
print("log1" + "Application Not found");
break;
case ApplicationStatus.Silent:
_showDialog(context, "Demo Application Currently in silent mode");
print("log1" + "Application silent");
break;
case ApplicationStatus.Running:
_showDialog(context, "Demo Application Currently in Running mode");
print("log1" + "Application Running");
break;
}
});
}
Final code here
Code:
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider<ThemeChanger>(
create: (context) => ThemeChanger(ThemeData.light()),
child: new App(),
);
}
}
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
final appState = Provider.of<ThemeChanger>(context);
return MaterialApp(
title: "WellFit",
theme: appState.getTheme(),
home: Scaffold(
body: Tabs(),
),
);
}
}
ThemeNotifier class
Code:
class ThemeChanger with ChangeNotifier {
ThemeData _themeData;
ThemeChanger(this._themeData);
getTheme() => _themeData;
setTheme(ThemeData themeData) {
_themeData = themeData;
notifyListeners();
}
}
Demo
​
Tips and Tricks
1. Download latest HMS Flutter plugin.
2. Set minSDK version to 29 or later.
3. Do not forget to click pug get after adding dependencies.
4. Do not forget to set data processing location.
5. Refer this URL for supported Devices list.
Conclusion
In this article, I have covered two services Dark-mode awareness and App status Awareness.
Using Dark-mode awareness we can easily identify which theme currently we activated in settings page.
Using App Status awareness we can monitor the application in which state like silent or running these two we covered in this article.
Thanks for reading! If you enjoyed this story, please click the Like button and Follow. Feel free to leave a Comment below.
Reference
Awareness Kit URL
Original Source

Integration of Push kit in Unity based game

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

Categories

Resources