Implementing Huawei Banner Ads — (Kotlin) - Huawei Developers

In this article, I will try to explain how you can easily implement Huawei Banner Ads (In Kotlin) to your project and monetize your application right away!
{
"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 Banner Ad
Banner ads are rectangular images that can be placed to the top, middle, or bottom of your app’s screen. Banner ads refresh automatically at regular intervals. When a user taps a banner ad, the user is redirected to the advertiser’s page in most cases.
To implement banner ads, you need to implement Huawei Ads Kit dependency to your project which I explained below.
How to Implement Ads Kit
Things you need to have
1) A Huawei Developer Account (It needs to be Enterprise Level account for monetization)
2) A Huawei phone with HMS 4.0.0.300 or later
3) A computer with Android Studio , Jdk 1.8, SDK platform 26 and Gradle 4.6 installed.
Things Need To Be Done Before Implementation
First things first HMS Core needs to be implemented to the your project.
After HMS Core implementation, Ads Kit dependency needs to be added in app level “build.gradle” file
Code:
<pre class="brush:java;toolbar:false;">dependencies {
...
//Huawei Ads Kit Dependency
implementation 'com.huawei.hms:ads-lite:13.4.32.300'
...
} </pre><p style="white-space: normal;">
</p><p style="white-space: normal;">4) Configure obfuscation scripts to prevent HUAWEI Ads kit from being obfuscated. Add the following two lines of code to the <strong>app/proguard-rules.pro</strong></p><p style="white-space: normal;"><strong>
</strong></p><pre class="brush:java;toolbar:false">-keep class com.huawei.openalliance.ad.** { *; }
-keep class com.huawei.hms.ads.** { *; }
</pre><p style="white-space: normal;">
</p><p style="white-space: normal;">After Completing the steps above. All you need to do is initialize Huwei Ads by calling HwAds.init() method in your application. Then the application is ready to implement all kind of various ad types which I will show below.</p><pre class="brush:java;toolbar:false">override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
...
// Initialize the HUAWEI Ads SDK.
HwAds.init(this);
...
} </pre>
Implementing Banner Ads
To implement Banner Ad, BannerView object needs to be initialized either with XML or directly in code.
Adding Banner Ads Through XML
Create BannerView in your XML
Code:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:hwads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".BannerAdsActivity">
...
<!--Adding BannerView Through XML-->
<com.huawei.hms.ads.banner.BannerView
android:id="@+id/hwBannerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
hwads:adId="testw6vs28auh3"
hwads:layout_constraintEnd_toEndOf="parent"
hwads:layout_constraintStart_toStartOf="parent"
hwads:layout_constraintTop_toTopOf="parent"
hwads:bannerSize="BANNER_SIZE_360_57"
/>
...
</androidx.constraintlayout.widget.ConstraintLayout>
After creating the your BannerView through XML file, call it from your class & load the add.
Code:
override fun onCreate(savedInstanceState: Bundle?) {
....
// Obtain BannerView based on the configuration in XML layout.
val adParam = AdParam.Builder().build();
hwBannerView.loadAd(adParam);
...
}
Run the application and the result will be like below.
Adding Banner Ads Programmatically Without XML
Lets create another Banner ad at the bottom of our view without using XML. All you need to do is creating & initializing banner ad , adding it to the specific layout, then loading the ad as below.
Code:
override fun onCreate(savedInstanceState: Bundle?) {
...
val adParam = AdParam.Builder().build();
val bannerView = BannerView(this);
// "testw6vs28auh3" is a dedicated test ad slot ID. To get real one, you need to have an enterprise level Huawei developer account.
bannerView.setAdId("testw6vs28auh3");
bannerView.setBannerAdSize(BannerAdSize.BANNER_SIZE_320_50);
val parentLayout = findViewById<ConstraintLayout>(R.id.clBannerMain);
val set = ConstraintSet();
// set view id, else getId() returns -1
bannerView.id = View.generateViewId()
parentLayout.addView(bannerView,0)
set.clone(parentLayout)
set.connect(bannerView.id, ConstraintSet.BOTTOM, parentLayout.id, ConstraintSet.BOTTOM, 0);
set.applyTo(parentLayout);
bannerView.loadAd(adParam)
...
}
When you run the code above you will see we have succesfully added a second banner ad to the bottom of the our view.
Code:
https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/023/106/056/0890090000023106056.20200827074704.78852832128128279354621703409783:50510914075520:2800:862740C17733B87A8CEAA65FD7B62221F9214A105D3414605B35C5EF96A0F1AE.png
Optional: Adding Ad Listener
After implementing banner ads to your project, if you want to proceed further, you can add Ad listener to listen ad events like AdLoaded is AdFailed is AdClicked etc. To do that, simply add an Ad Listener to your project like below
Code:
override fun onCreate(savedInstanceState: Bundle?) {
...
val adListener = object : AdListener() {
override fun onAdImpression() {
super.onAdImpression()
}
override fun onAdFailed(p0: Int) {
super.onAdFailed(p0)
}
override fun onAdLeave() {
super.onAdLeave()
}
override fun onAdClicked() {
super.onAdClicked()
}
override fun onAdClosed() {
super.onAdClosed()
}
override fun onAdOpened() {
super.onAdOpened()
}
override fun onAdLoaded() {
super.onAdLoaded()
}
}
//Add Ad Listener to which ad you want to listen.
bannerView.adListener = adListener
....
}
As you can see, it is really easy to implement banner ads to your android application with Huawei Ads Kit. Stay tuned for other ad types. You can find the github project below.
Resources
Disav0wed/Huawei_Banner_Ads_Demo:https://github.com/Disav0wed/Huawei_Banner_Ads_Demo
Official Huawei Documentation:https://developer.huawei.com/consumer/en/doc/development/HMS-Guides/ads-sdk-guide-banner
Codelab:https://developer.huawei.com/consumer/en/codelab/HUAWEIAdsSDK-BannerAds/index.html#2

Related

Huawei Ads Kit — Banner Ads

In this article, I will try to explain how you can easily implement Huawei Banner Ads to your project and monetize your application right away!
{
"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 Banner Ad
Banner ads are rectangular images that can be placed to the top, middle, or bottom of your app’s screen. Banner ads refresh automatically at regular intervals. When a user taps a banner ad, the user is redirected to the advertiser’s page in most cases.
To implement banner ads, you need to implement Huawei Ads Kit dependency to your project which I explained below.
How to Implement Ads Kit
Things you need to have
1) A Huawei Developer Account (It needs to be Enterprise Level account for monetization)
2) A Huawei phone with HMS 4.0.0.300 or later
3) A computer with Android Studio , Jdk 1.8, SDK platform 26 and Gradle 4.6 installed.
Things Need To Be Done Before Implementation
First things first HMS Core needs to be implemented to the your project. To see how to implement HMS Core please refer this link.
After HMS Core implementation, Ads Kit dependency needs to be added in app level “build.gradle” file
Code:
dependencies {
...
//Huawei Ads Kit Dependency
implementation 'com.huawei.hms:ads-lite:13.4.32.300'
...
}
4) Configure obfuscation scripts to prevent HUAWEI Ads kit from being obfuscated. Add the following two lines of code to the app/proguard-rules.pro
Code:
-keep class com.huawei.openalliance.ad.** { *; }
-keep class com.huawei.hms.ads.** { *; }
After Completing the steps above. All you need to do is initialize Huwei Ads by calling HwAds.init() method in your application. Then the application is ready to implement all kind of various ad types which I will show below.
Code:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
...
// Initialize the HUAWEI Ads SDK.
HwAds.init(this);
...
}
Implementing Banner Ads
To implement Banner Ad, BannerView object needs to be initialized either with XML or directly in code.
Adding Banner Ads Through XML
Create BannerView in your XML
Code:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:hwads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".BannerAdsActivity">
...
<!--Adding BannerView Through XML-->
<com.huawei.hms.ads.banner.BannerView
android:id="@+id/hwBannerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
hwads:adId="testw6vs28auh3"
hwads:layout_constraintEnd_toEndOf="parent"
hwads:layout_constraintStart_toStartOf="parent"
hwads:layout_constraintTop_toTopOf="parent"
hwads:bannerSize="BANNER_SIZE_360_57"
/>
...
</androidx.constraintlayout.widget.ConstraintLayout>
Call it from your class & load the add.
Code:
override fun onCreate(savedInstanceState: Bundle?) {
....
// Obtain BannerView based on the configuration in XML layout.
val adParam = AdParam.Builder().build();
hwBannerView.loadAd(adParam);
...
}
Run the application and the result will be like below.
Adding Banner Ads Programmatically Without XML
Lets create another Banner ad at the bottom of our view without using XML. All you need to do is creating & initializing banner ad , adding it to the specific layout, then loading the ad as below.
Code:
override fun onCreate(savedInstanceState: Bundle?) {
...
val adParam = AdParam.Builder().build();
val bannerView = BannerView(this);
// "testw6vs28auh3" is a dedicated test ad slot ID. To get real one, you need to have an enterprise level Huawei developer account.
bannerView.setAdId("testw6vs28auh3");
bannerView.setBannerAdSize(BannerAdSize.BANNER_SIZE_320_50);
val parentLayout = findViewById<ConstraintLayout>(R.id.clBannerMain);
val set = ConstraintSet();
// set view id, else getId() returns -1
bannerView.id = View.generateViewId()
parentLayout.addView(bannerView,0)
set.clone(parentLayout)
set.connect(bannerView.id, ConstraintSet.BOTTOM, parentLayout.id, ConstraintSet.BOTTOM, 0);
set.applyTo(parentLayout);
bannerView.loadAd(adParam)
...
}
As shown above, we have successfully added second banner ad to our program without touching the xml.
Optional: Adding Ad Listener
After implementing banner ads to your project, if you want to proceed further, you can add Ad listener to listen ad events like is AdLoaded is AdFailed is AdClicked etc.
Code:
override fun onCreate(savedInstanceState: Bundle?) {
...
val adListener = object : AdListener() {
override fun onAdImpression() {
super.onAdImpression()
}
override fun onAdFailed(p0: Int) {
super.onAdFailed(p0)
}
override fun onAdLeave() {
super.onAdLeave()
}
override fun onAdClicked() {
super.onAdClicked()
}
override fun onAdClosed() {
super.onAdClosed()
}
override fun onAdOpened() {
super.onAdOpened()
}
override fun onAdLoaded() {
super.onAdLoaded()
}
}
//Add Ad Listener to which ad you want to listen.
bannerView.adListener = adListener
....
}
As you can see, it is really easy to implement banner ads to your android application with Huawei Ads Kit. Stay tuned for other ad types. You can find the github project below.
Resources
https://github.com/Disav0wed/Huawei_Banner_Ads_Demo
https://developer.huawei.com/consumer/en/doc/development/HMS-Guides/ads-sdk-guide-banner
https://developer.huawei.com/consumer/en/codelab/HUAWEIAdsSDK-BannerAds/index.html#2
Related Links
Thanks to Ibrahim R. Serpici for this article.
Original post: https://medium.com/huawei-developers/huawei-ads-kit-banner-ads-1130da8d40da

Implement the Automatic Bill Number Input Function Using ML Kit’s Text Recognition

More information like this, you can visit HUAWEI Developer Forum​
Introduction
In the previous post, we looked at how to use HUAWEI ML Kit’s card recognition function to implement the card binding function. With this function, users only need to provide a photo of their card, and your app will automatically recognize all of the key information. That makes entering card information much easier, but can we do the same thing for bills or discount coupons? Of course we can! In this post, I will show you how to implement automatic input of bill numbers and discount codes using HUAWEI ML Kit’s text recognition function.
Application
Text recognition is useful in a huge range of situations. For example, if you scan the following bill, indicate that the bill service number starts with “NO.DE SERVICIO”, and limit the length to 12 characters, you can quickly get the bill service number “123456789123” using the text recognition.
{
"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"
}
Similarly, if you scan the discount coupon below, start the discount code with “FAVE-” and limit the length to 4 characters, you’ll get the discount code “8329”, and can then complete the payment.
Pretty useful, right? You can also customize the information you want your app to recognize.
Integrating Text Recognition
So, let’s look at how to process bill numbers and discount codes.
1. Preparations
You can find detailed information about the preparations you need to make on the HUAWEI Developer.
Here, we’ll just look at the most important procedures.
1.1 Configure the Maven Repository Address in the Project-Level build.gradle File
Code:
buildscript {
repositories {
...
maven {url 'https://developer.huawei.com/repo/'}
}
}
dependencies {
...
classpath 'com.huawei.agconnect:agcp:1.3.1.300'
}
allprojects {
repositories {
...
maven {url 'https://developer.huawei.com/repo/'}
}
}
1.2 Add Configurations to the File Header
Once you’ve integrated the SDK, add the following configuration to the file header:
Code:
apply plugin: 'com.android.application'
apply plugin: 'com.huawei.agconnect'
1.3 Configure SDK Dependencies in the App-Level build.gradle File
Code:
dependencies {
// Import the base SDK.
implementation 'com.huawei.hms:ml-computer-vision-ocr:2.0.1.300'
// Import the Latin character recognition model package.
implementation 'com.huawei.hms:ml-computer-vision-ocr-latin-model:2.0.1.300'
// Import the Japanese and Korean character recognition model package.
implementation 'com.huawei.hms:ml-computer-vision-ocr-jk-model:2.0.1.300'
// Import the Chinese and English character recognition model package.
implementation 'com.huawei.hms:ml-computer-vision-ocr-cn-model:2.0.1.300'
}
1.4 Add these Statements to the AndroidManifest.xml File so the Machine Learning Model can Automatically Update
Code:
<manifest>
...
<meta-data
android:name="com.huawei.hms.ml.DEPENDENCY"
android:value="ocr" />
...
</manifest>
1.5 Apply for the Camera Permission
Code:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
2. Code Development
2.1 Create an Analyzer
Code:
MLTextAnalyzer analyzer = new MLTextAnalyzer.Factory(context).setLanguage(type).create();
2.2 Set the Recognition Result Processor to Bind with the Analyzer
Code:
analyzer.setTransactor(new OcrDetectorProcessor());
2.3 Call the Synchronous API
Use the built-in LensEngine of the SDK to create an object, register the analyzer, and initialize camera parameters.
Code:
lensEngine = new LensEngine.Creator(context, analyzer)
.setLensType(LensEngine.BACK_LENS)
.applyDisplayDimension(width, height)
.applyFps(30.0f)
.enableAutomaticFocus(true)
.create();
2.4 Call the run Method to Start the Camera and Read the Camera Streams for the Recognition
Code:
try {
lensEngine.run(holder);
} catch (IOException e) {
// Exception handling logic.
Log.e("TAG", "e=" + e.getMessage());
}
2.5 Process the Recognition Result As Required
Code:
public class OcrDetectorProcessor implements MLAnalyzer.MLTransactor<MLText.Block> {
@Override
public void transactResult(MLAnalyzer.Result<MLText.Block> results) {
SparseArray<MLText.Block> items = results.getAnalyseList();
// Process the recognition result as required. Only the detection results are processed.
// Other detection-related APIs provided by ML Kit cannot be called.
…
}
@Override
public void destroy() {
// Callback method used to release resources when the detection ends.
}
}
2.6 Stop the Analyzer and Release the Detection Resources When the Detection Ends
Code:
if (analyzer != null) {
try {
analyzer.stop();
} catch (IOException e) {
// Exception handling.
}
}
if (lensEngine != null) {
lensEngine.release();
}
Demo Effect
And that’s it! Remember that you can expand this capability if you need to. Now, let’s look at how to scan travel bills.
And here’s how to scan discount codes to quickly obtain online discounts and complete payments.
Github Source Code
https://github.com/HMS-Core/hms-ml-demo/tree/master/Receipt-Text-Recognition
Awsome work !!

Monetize Video Player: Huawei Roll Ads and Video Kit

Introduction
In this article, I would like to introduce the latest addition to Huawei Ads Kit, Roll Ads.
Roll Ads is an ads that will play before the video or stream content can be consumed by the user, this leads to a smooth User Experience and is a good source of revenue for App Developers.
I will also introduce Video Kit, a video player kit that enables developer to develop a video player or streaming services in few simple steps.
Implementing Roll Ads
Please ensure you have created your app on AGC Console, and setup the HMS Core Plugin.
You can follow the guide here.
Lets add the ads dependencies:
Code:
implementation 'com.huawei.hms:ads-lite:13.4.33.300'
Next, we can init the ads from our Application class:
Code:
override fun onCreate() {
super.onCreate()
// init HMS Ads Kit
HwAds.init(this)
}
Lets add our Instream Ads View on our activity xml:
Code:
<RelativeLayout
android:id="@+id/instream_ad_container"
android:layout_width="match_parent"
android:layout_height="200dp"
android:visibility="visible">
<!-- Roll ad view. -->
<com.huawei.hms.ads.instreamad.InstreamView
android:id="@+id/instream_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
To test our Ads, we can use the dedicated roll ads slot id: "testy3cglm3pj0"
Code:
val builder = InstreamAdLoader.Builder(this, "testy3cglm3pj0")
And we can set our ads as below
Code:
val adloader = builder.setTotalDuration(30)
.setMaxCount(1)
.setInstreamAdLoadListener(object : InstreamAdLoadListener {
override fun onAdFailed(p0: Int) {
}
override fun onAdLoaded(p0: MutableList<InstreamAd>?) {
instream_view.setInstreamAds(p0)
}
}).build()
adloader.loadAd(AdParam.Builder().build())
After setting up all this, you should be able to run the app and you will see a roll ads being played.
{
"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"
}
Implementing Video Kit
Now lets add Video Kit dependencies to our build.gradle
Code:
implementation "com.huawei.hms:videokit-player:1.0.1.300"
We can initialize our video kit (wise player) in Application class as well, like so:
First, let's add a reference for our wisePlayerFactory
Code:
companion object {
lateinit var wisePlayerFactory: WisePlayerFactory
}
We can initialize the object on Application Create:
Code:
private fun initPlayer() {
// DeviceId test is used in the demo, specific access to incoming deviceId after encryption
val factoryOptions = WisePlayerFactoryOptions.Builder().setDeviceId("test-device1").build()
WisePlayerFactory.initFactory(this, factoryOptions, initFactoryCallback)
}
override fun onCreate() {
super.onCreate()
HwAds.init(this)
initPlayer()
}
Lastly, we need create the callback and getter/setter for our wisePlayerFactory
Code:
private val initFactoryCallback: InitFactoryCallback = object : InitFactoryCallback {
override fun onSuccess(wisePlayerFactory: WisePlayerFactory) {
setWisePlayerFactory(wisePlayerFactory)
}
override fun onFailure(errorCode: Int, reason: String) {
}
}
fun getWisePlayerFactory(): WisePlayerFactory? {
return MyApplication.wisePlayerFactory
}
private fun setWisePlayerFactory(wisePlayerFactory: WisePlayerFactory) {
MyApplication.wisePlayerFactory = wisePlayerFactory
}
On our activity xml, we need to create SurfaceView to be attached to our WisePlayer
Code:
<FrameLayout
android:id="@+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone">
<SurfaceView
android:id="@+id/surface_view"
android:layout_width="match_parent"
android:layout_height="200dp" />
</FrameLayout>
Combining the two
Now that we have both kits setup, lets combine them.
We will only start the video once the ads is finished displayed.
Let's add a listener to our Instream Ads so that we know once the ads is finished playing
Code:
instream_view.setInstreamMediaStateListener(object : InstreamMediaStateListener{
override fun onMediaPause(p0: Int) {
}
override fun onMediaProgress(p0: Int, p1: Int) {
}
override fun onMediaCompletion(p0: Int) {
// Initialize our video player
player = MyApplication.getWisePlayerFactory().createWisePlayer()
// video will be played once the video is ready to load the data
player.setReadyListener {
player.start()
}
player.setVideoType(0);
player.setBookmark(10000);
player.setCycleMode(1);
// set the video to play
player.setPlayUrl("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4")
player.setView(surface_view);
// initiate video loading
player.ready()
// hide the ads container, and show the video player
instream_ad_container.visibility = View.GONE
frame_layout.visibility = View.VISIBLE
}
override fun onMediaError(p0: Int, p1: Int, p2: Int) {
}
override fun onMediaStart(p0: Int) {
}
override fun onMediaStop(p0: Int) {
}
})
Once you combined the two, you will see the stream/video will be played after the ads finished loading:
Tips & Trick
Do ensure that your instream view and wise player view size is similar, to provide a much better viewing experience for the user.
You cann add a skip button on the Roll Ads that will be only enabled after a certain time (for example 5 secs) so that the user can jump to the content after 5 sec of ads.
Conclusion
From this article, I hope this will help you to understand how to integrate our Roll Ads as well as Video Kit.
As you can see, implementation is very straight forward, I hope you guys can give it a try.
Do left a comment if you have any suggestions/questions.
Thank you!
Reference
Roll Ads - https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/publisher-service-instream-0000001058253743
Video Kit - https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides-V5/init-player-0000001050199407-V5 and
https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/basic-play-process-0000001050197362

Intermediate: Consult Doctor for Disease using Huawei Kits (Account, Crash and Analytics) in Android App

Overview
In this article, I will create a Doctor Consult android application in which I will integrate HMS Core kits such as Huawei ID, Crash and Analytics.
Huawei ID Service Introduction
Huawei ID login provides you with simple, secure, and quick sign-in and authorization functions. Instead of entering accounts and passwords and waiting for authentication, users can just tap the Sign in with HUAWEI ID button to quickly and securely sign in to your app with their HUAWEI IDs.
Prerequisite
Huawei Phone EMUI 3.0 or later.
Non-Huawei phones Android 4.4 or later (API level 19 or higher).
HMS Core APK 4.0.0.300 or later
Android Studio
AppGallery Account.
App Gallery Integration process
Sign In and Create or Choose a project on AppGallery Connect portal.
Navigate to Project settings and download the configuration file.
Navigate to General Information, and then provide Data Storage location.
App Development
Create A New Project.
Configure Project Gradle.
Code:
buildscript {
repositories {
google()
jcenter()
maven { url 'https://developer.huawei.com/repo/' }
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.1"
classpath 'com.google.gms:google-services:4.3.5'
classpath 'com.huawei.agconnect:agcp:1.3.1.300'
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://developer.huawei.com/repo/' }
}
}
task clean(type: Delete) {
Configure App Gradle.
Code:
api 'com.huawei.hms:dynamicability:1.0.11.302'
implementation 'com.huawei.agconnect:agconnect-auth:1.4.1.300'
implementation 'com.huawei.hms:hwid:5.3.0.302'
implementation 'com.huawei.hms:ads-lite:13.4.30.307'
implementation 'com.huawei.agconnect:agconnect-remoteconfig:1.6.0.300'
implementation 'com.huawei.hms:hianalytics:5.0.3.300'
implementation 'com.huawei.agconnect:agconnect-crash:1.4.1.300'
Configure AndroidManifest.xml.
Code:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Create Activity class with XML UI.
MainActivity:
Code:
public class MainActivity extends AppCompatActivity {
Toolbar t;
DrawerLayout drawer;
EditText nametext;
EditText agetext;
ImageView enter;
RadioButton male;
RadioButton female;
RadioGroup rg;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
drawer = findViewById(R.id.draw_activity);
t = (Toolbar) findViewById(R.id.toolbar);
nametext = findViewById(R.id.nametext);
agetext = findViewById(R.id.agetext);
enter = findViewById(R.id.imageView7);
male = findViewById(R.id.male);
female = findViewById(R.id.female);
rg=findViewById(R.id.rg1);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, t, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView nav = findViewById(R.id.nav_view);
enter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String name = nametext.getText().toString();
String age = agetext.getText().toString();
String gender= new String();
int id=rg.getCheckedRadioButtonId();
switch(id)
{
case R.id.male:
gender = "Mr.";
break;
case R.id.female:
gender = "Ms.";
break;
}
Intent symp = new Intent(MainActivity.this, SymptomsActivity.class);
symp.putExtra("name",name);
symp.putExtra("gender",gender);
startActivity(symp);
}
});
nav.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
switch(menuItem.getItemId())
{
case R.id.nav_sos:
Intent in = new Intent(MainActivity.this, call.class);
startActivity(in);
break;
case R.id.nav_share:
Intent myIntent = new Intent(Intent.ACTION_SEND);
myIntent.setType("text/plain");
startActivity(Intent.createChooser(myIntent,"SHARE USING"));
break;
case R.id.nav_hosp:
Intent browserIntent = new Intent(Intent.ACTION_VIEW);
browserIntent.setData(Uri.parse("https://www.google.com/maps/search/hospitals+near+me"));
startActivity(browserIntent);
break;
case R.id.nav_cntus:
Intent c_us = new Intent(MainActivity.this, activity_contact_us.class);
startActivity(c_us);
break;
}
drawer.closeDrawer(GravityCompat.START);
return true;
}
});
}
}
App Build Result​
{
"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"
}
Tips and Tricks
Identity Kit displays the HUAWEI ID registration or sign-in page first. You can use the functions provided by Identity Kit only after signing in using a registered HUAWEI ID.
Conclusion
In this article, we have learned how to integrate Huawei ID in Android application. After completely read this article user can easily implement Huawei ID in the Doctor Consult application.
Thanks for reading this article. Be sure to like and comment to this article, if you found it helpful. It means a lot to me.
References
HMS Docs:
https://developer.huawei.com/consum.../HMSCore-Guides/introduction-0000001050048870

Intermediate: Know Your Doctor using Huawei Kits (Account, Crash and Analytics) in Android App.

Overview
In this article, I will create a DoctorConsultApp android application in which I will integrate HMS Core kits such as Huawei ID, Crash and Analytics.
Huawei ID Service Introduction
Huawei ID login provides you with simple, secure, and quick sign-in and authorization functions. Instead of entering accounts and passwords and waiting for authentication, users can just tap the Sign in with HUAWEI ID button to quickly and securely sign in to your app with their HUAWEI IDs.
Prerequisite
Huawei Phone EMUI 3.0 or later.
Non-Huawei phones Android 4.4 or later (API level 19 or higher).
HMS Core APK 4.0.0.300 or later
Android Studio
AppGallery Account.
App Gallery Integration process
Sign In and Create or Choose a project on AppGallery Connect portal.
Navigate to Project settings and download the configuration file.
Navigate to General Information, and then provide Data Storage location.
App Development
Create A New Project.
Configure Project Gradle.
Code:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
maven {url 'https://developer.huawei.com/repo/'}
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.1"
classpath 'com.huawei.agconnect:agcp:1.4.2.300'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven {url 'https://developer.huawei.com/repo/'}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Configure App Gradle.
Code:
implementation 'com.huawei.hms:identity:5.3.0.300'
implementation 'com.huawei.agconnect:agconnect-auth:1.4.1.300'
implementation 'com.huawei.hms:hwid:5.3.0.302'
Configure AndroidManifest.xml.
Code:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
Create Activity class with XML UI.
MainActivity:
Code:
public class MainActivity extends AppCompatActivity {
Toolbar t;
DrawerLayout drawer;
EditText nametext;
EditText agetext;
ImageView enter;
RadioButton male;
RadioButton female;
RadioGroup rg;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
drawer = findViewById(R.id.draw_activity);
t = (Toolbar) findViewById(R.id.toolbar);
nametext = findViewById(R.id.nametext);
agetext = findViewById(R.id.agetext);
enter = findViewById(R.id.imageView7);
male = findViewById(R.id.male);
female = findViewById(R.id.female);
rg=findViewById(R.id.rg1);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, t, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView nav = findViewById(R.id.nav_view);
enter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String name = nametext.getText().toString();
String age = agetext.getText().toString();
String gender= new String();
int id=rg.getCheckedRadioButtonId();
switch(id)
{
case R.id.male:
gender = "Mr.";
break;
case R.id.female:
gender = "Ms.";
break;
}
Intent symp = new Intent(MainActivity.this, SymptomsActivity.class);
symp.putExtra("name",name);
symp.putExtra("gender",gender);
startActivity(symp);
}
});
nav.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
switch(menuItem.getItemId())
{
case R.id.nav_sos:
Intent in = new Intent(MainActivity.this, call.class);
startActivity(in);
break;
case R.id.nav_share:
Intent myIntent = new Intent(Intent.ACTION_SEND);
myIntent.setType("text/plain");
startActivity(Intent.createChooser(myIntent,"SHARE USING"));
break;
case R.id.nav_hosp:
Intent browserIntent = new Intent(Intent.ACTION_VIEW);
browserIntent.setData(Uri.parse("https://www.google.com/maps/search/hospitals+near+me"));
startActivity(browserIntent);
break;
case R.id.nav_cntus:
Intent c_us = new Intent(MainActivity.this, activity_contact_us.class);
startActivity(c_us);
break;
}
drawer.closeDrawer(GravityCompat.START);
return true;
}
});
}
}
App Build Result
{
"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"
}
Tips and Tricks
Identity Kit displays the HUAWEI ID registration or sign-in page first. You can use the functions provided by Identity Kit only after signing in by a registered HUAWEI ID.
Conclusion
In this article, we have learned how to integrate Huawei ID in Android application. After completely read this article, user can easily implement Huawei ID in DoctorConsultApp application.
Thanks for reading this article. Be sure to like and comment to this article, if you found it helpful. It means a lot to me.
References
HMS Docs:
https://developer.huawei.com/consum.../HMSCore-Guides/introduction-0000001050048870
Video Training:
https://developer.huawei.com/consumer/en/training/course/video/101583015541549183

Categories

Resources