Integrate Ads kit in Flutter Application - Huawei Developers

More articles like this, you can visit HUAWEI Developer Forum
In this article we will be working on HMS Ads kit and integrate into a flutter application.
In first part we will work on the setup part and in second part we will work on implementing the ads in application.
Step 1: Create a project in AGC console
Step 2: You have to install flutter and dart plugin to android studio. Go to File -> Settings -> Plugins
{
"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"
}
Once both are installed it will show you an option to create a new project in flutter.
To confirm run the below command in terminal “flutter doctor”
If you are still facing any issue in setup please comment below and I will make sure to resolve them.
Step 3: Download the folder and add in in your workspace where your flutter project resides.
https://developer.huawei.com/consumer/en/doc/HMS-Plugin-Library-V1/flutter-sdk-download-0000001050196675-V1
Step 4: Open pubspec.yaml file and add the below code.
Code:
huawei_ads:
path: ../huawei_ads/
..means to go 2 step backwards in folder and Huawei_ads is the folder name which you downloaded in previous step.
Once you change the pubspec.yaml file it will ask you to get the dependencies.
Click on pub get button highlighted above and you can get the latest dependencies.
Below message should be shown if the step goes successful.
To confirm the above step is successful you can also open external libraries and check flutter plugin added to it.
Step 5: Open the android project level gradle file and add below code.
Code:
dependencies {
classpath 'com.huawei.agconnect:agcp:1.2.1.301'
}
add below code in buildscript and allprojects section of gradle file
Code:
maven { url 'https://developer.huawei.com/repo/' }
Step 6: Go to app level gradle file and add below dependencies and agc services
Code:
implementation 'com.huawei.hms:ads-lite:13.4.30.301'
implementation 'com.huawei.hms:ads-consent:3.4.28.305'
implementation 'com.huawei.hms:ads-identifier:3.4.28.313'
implementation 'com.huawei.hms:ads-installreferrer:3.4.28.313'
Code:
apply plugin: 'com.huawei.agconnect'
Step 7: Add the agconnect-services.json into android -> app folder
Till here your initial setup is completed.
Now you have to create a UI where you can showcase your ads.
I am using a RaisedButton in order to call the logic of ads creation. You can use your own triggering mechanism in order to show the ads.
Banner Ads:
Code:
import 'package:flutter/material.dart';
import 'package:huawei_ads/hms_ads_lib.dart';
class BannerAds extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Align(
alignment: Alignment.topCenter,
child: RaisedButton(
child: Text(
'Load Banner Ads',
),
onPressed: () {
BannerAd _bannerAd = createBannerAd();
_bannerAd
..loadAd()
..show();
},
),
);
}
}
BannerAd createBannerAd() {
return BannerAd(
adUnitId: "testw6vs28auh3",
size: BannerAdSize(width: 360, height: 57),
adParam: AdParam.build(),
);
}
Make sure you use the proper imports
Create a method which returns BannerAd
I am using test add id but you can use your own add id.
I am showcasing with 2 banner size but you can modify them according to your need.
Call the load add and show add method to show the banner ad.
Below is the table from which you can choose ad size.
Below are the screenshot for Banner Ads
Splash Ads:
Code:
import 'package:flutter/material.dart';
import 'package:huawei_ads/hms_ads_lib.dart';
class SplashAds extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Align(
alignment: Alignment.topCenter,
child: RaisedButton(
child: Text(
'Load Splash Ads',
),
onPressed: () {
SplashAd splashAd = createSplash();
splashAd
..loadAd(
adUnitId: "testq6zq98hecj",
orientation: SplashAdOrientation.portrait,
adParam: AdParam.build(),
topMargin: 1);
},
),
);
}
}
SplashAd createSplash() => SplashAd(
adType: SplashAdType.above,
ownerText: 'Owner Text',
footerText: 'Footer Text',
loadListener: (SplashAdLoadEvent event, {int errorCode}) {
print("SplashAdLoadEvent : $event");
if (event == SplashAdLoadEvent.dismissed) {
//Handle Dismiss logic here
}
});
Create a method which returns SplashAd
I am using test add id but you can use your own add id.
topMargin can increase the margin space between splash and top border.
You can also define the orientation of add as well.
You can customize Owner text and Footer Text.
Below are the screenshot for Splash Ads
Interstitial Ads
Code:
import 'package:flutter/material.dart';
import 'package:huawei_ads/adslite/interstitial/interstitial_ad.dart';
class InterstitialAds extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Align(
alignment: Alignment.topCenter,
child: RaisedButton(
child: Text(
'Load Interstitial Ads',
),
onPressed: () {
InterstitialAd _interstitialAd = createInterstitialAd();
_interstitialAd
..loadAd()
..show();
},
),
);
}
}
InterstitialAd createInterstitialAd() {
return InterstitialAd(
adUnitId: "teste9ih9j0rc3",
);
}
Create a method which returns Interstitial Ad
I am using test add id but you can use your own add id.
Below are the screenshot for Interstitial Ad.
I hope you with the above snippets you can implement above three categories of ads.

Related

Create photo Animations App with Huawei Image Kit

More information like this, you can visit HUAWEI Developer Forum​
Original link: https://forums.developer.huawei.com/forumPortal/en/topicview?tid=0202327021435990014&fid=0101187876626530001
Introduction
Image kit provides 2 SDKs, the image vision SDK and Image Render SDK. We can add animations to your photos in minutes. The image render service provides 5 basic animation effects and 9 advanced effects.
Requirements
1. Huawei Device (Currently it will not support non-Huawei devices).
2. EMUI 8.1 above.
3. Minimum Android SDK version 26.
Use Cases
1. Image post processing: It provides 20 effects for the image processing and achieving high-quality image.
2. Theme design: Applies animations lock screens, wallpapers and themes
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
Integration
Create Application in Android Studio.
App level gradle depenencies.
Code:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
Image kit dependencies
Code:
implementation 'com.huawei.hms:image-render:1.0.2.302'
Kotlin dependencies
Code:
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
Root level gradle dependencies
Code:
maven {url 'http://developer.huawei.com/repo/'}
classpath 'com.huawei.agconnect:agcp:1.3.1.300'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
To use the image render API, we need to provide resource files including images and manifest.xml files. Using image render service will parse the manifest.xml
Below parameters can be used in ImageRender API.
{
"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 Instance for ImageRenderImpl by calling the getInstance() method. To call this method app must implement callback method OnSuccess(), OnFailure(). If the ImageRender instance is successfully obtained.
Code:
fun initImageRender() {
ImageRender.getInstance(this, object : RenderCallBack {
override fun onSuccess(imageRender: ImageRenderImpl) {
showToast("ImageRenderAPI success")
imageRenderApi = imageRender
useImageRender()
}
override fun onFailure(i: Int) {
showToast("ImageRenderAPI failure, errorCode = $i")
}
})
}
Initialize Render service we need to pass source path and authJson, we can use the service after successfully authenticated.
Code:
fun useImageRender() {
val initResult: Int = imageRenderApi!!.doInit(sourcePath, authJson)
showToast("DoInit result == $initResult")
if (initResult == 0) {
val renderView: RenderView = imageRenderApi!!.getRenderView()
if (renderView.resultCode == ResultCode.SUCCEED) {
val view = renderView.view
if (null != view) {
frameLayout!!.addView(view)
}
}
} else {
showToast("Do init fail, errorCode == $initResult")
}
}
The Image Render service parses the image and script in sourcepath getRenderView() API will return the rendered views to the app.
User interaction is supported for advanced animation views.
Code:
fun initAuthJson() {
try {
authJson = JSONObject(string)
} catch (e: JSONException) {
System.out.println(e)
}
}
Code:
fun playAnimation(filterType: String) {
if (!Utils.copyAssetsFilesToDirs(this, filterType, sourcePath!!)) {
showToast("copy files failure, please check permissions")
return
}
if (imageRenderApi != null && frameLayout!!.childCount > 0) {
frameLayout!!.removeAllViews()
imageRenderApi!!.removeRenderView()
val initResult: Int = imageRenderApi!!.doInit(sourcePath, authJson)
showToast("DoInit result == $initResult")
if (initResult == 0) {
val renderView: RenderView = imageRenderApi!!.getRenderView()
if (renderView.resultCode == ResultCode.SUCCEED) {
val view = renderView.view
if (null != view) {
frameLayout!!.addView(view)
}
}
} else {
showToast("Do init fail, errorCode == $initResult")
}
}
}
Result:
Reference:
To know more about Image kit, check below URLs.
Image Kit:
https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides-V5/render-service-dev-0000001050197008-V5
Image Editor Article:
https://forums.developer.huawei.com/forumPortal/en/topicview?tid=0201320928748890264&fid=0101187876626530001
GitHub:
https://github.com/DTSE-India-Community/HMS-Image-Kit

Tic Tac Toe Game using HTML5 Quick Game - Part 2

{
"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 my last article, we can learn the following:
What is Quick game?
Feature and advantage of Quick game.
Development procedure.
Installing development tools.
If you have not yet read my previous article read it here to understand more about quick game. Just to summarize in my previous article we have installed project and created the application in Quick app IDE.
In this article, we can learn the following:
Creating Quick Game.
Generating and configuring a certificate fingerprint.
Enabling Game service and Account kit.
Creating Quick Game
Step 1: Sign in to AppGallery Connect and click My apps.
Step 2: Click New App.
Step 3: Add all required information, then click OK.
Parameters information
Step 4: Navigate to project setting > General information add package details.
Step 5: Add Default data processing location.
Generating and configuring a certificate fingerprint.
Create certificate
Step 1: Open Quick App IDE and open an existing project or create new project.
Step 2: Choose Tools > Certificate
Step 3: If signature is not yet created, select Create else if already exist select Import.
Step 4: Add necessary information and click Create.
Step 5: Copy SHA-256 certificate fingerprint from output.
Configure the Certificate fingerprint in AppGallery
Step 1: Sign in to AppGallery and click My project
Step 2: Select the project which you want to configure the certificate fingerprint.
Step 3: Navigate to Project Settings > General information in the App information and enter the copied SHA-256 certificate.
Enable Game service.
Step 1: Sign in to AppGallery and click My project.
Step 2: Select the project which you want to enable Game service and account kit.
Step 3: Navigate to Project Settings > Manage API and enable account kit and Game service.
Build the HTML5 Quick Game
HTML:
<!-- HTML5 Quick Game Access Guidance -->
<!-- https://developer.huawei.com/consumer/en/doc/development/quickApp-Guides/quickgame-develop-h5-game-->
<template>
<div class="doc-page">
<!-- Replace the link to the HTML5 game -->
<web class="web-page" src="{{gameUrl}}" type="game" trustedurl="{{list}}" onpagestart="onPageStart"
fullscreendirection="{{fullscreenDirection}}" jumppolicy="{{linkJumpPolicy}}" multiwindow="{{openMultiwindow}}"
onpagefinish="onPageFinish" ontitlereceive="onTitleReceive" onerror="onError" id="web"
allowthirdpartycookies="{{allowThirdPartyCookies}}">
</web>
</div>
</template>
<style>
.doc-page {
flex-direction: column;
flex-direction: column;
justify-content: center;
align-content: center;
align-items: center;
}
.web-page {
width: 100%;
height: 100%;
}
</style>
<script>
import router from "@system.router"
import prompt from '@system.prompt'
export default {
props: ['websrc'],
data: {
title: "",
// TODO Replace the link to the H5 game
gameUrl: "https://codepen.io/timrijkse/full/XjLGKv/",
// Attribute allowthirdpartycookies, indicates whether cookies can be delivered in cross-domain mode.
// If you need login Google Account or Other Account, Please set TRUE.
allowThirdPartyCookies: true,
//Attribute fullscreendirection,controls the direction when the webpage requests full screen.
//If you want the full screen orientation to be vertical, please set it to portrait.
//The default value is landscape
fullscreenDirection: "landscape",
//If you want the ads in the game to be opened in the browser, please set the value of openMultiwindow
// to true and the value of linkJumpPolicy to browser
linkJumpPolicy: "default",
openMultiwindow: false,
// Here the trust list settings, when the loading page has multiple addresses, such as the successful loading of the login address and the inconsistent entry address, it needs to set the trust list to do so.
list: ["new RegExp('https?.*')"],
},
onPageStart(e) {
console.info('pagestart: ' + e.url)
},
// Each page switch triggers
onPageFinish(e) {
console.info('pagefinish: ' + e.url, e.canBack, e.canForward)
},
onTitleReceive(e) {
this.title = e.title;
},
onError(e) {
console.info('pageError : ' + e.errorMsg)
},
onMessage(e) {
console.info('onmessage e = ' + e.message + ", url = " + e.url);
prompt.showToast({
message: e.message + ': ' + e.url
})
},
isCanForward() {
this.$element('web').canForward({
callback: function (e) {
if (e) {
this.$element('web').forward();
}
}.bind(this)
})
},
isCanBack() {
this.$element('web').canBack({
callback: function (e) {
if (e) {
this.$element('web').back();
} else {
router.back();
}
}.bind(this)
})
},
onShow: function () {
console.info(" onshow");
},
onHide: function () {
console.info(" onHide");
},
onBackPress() {
const prompt = require('@system.prompt')
prompt.showDialog({
message: 'Whether to quit the html5 game?',
buttons: [
{
text: 'Cancel'
},
{
text: 'Exit'
}
],
success: (data) => {
console.log('handling callback', data.index)
if (data.index === 1) {
this.$app.exit()
}
},
cancel: function () {
console.log('handling cancel')
},
fail: function (data, code) {
console.log(`handling fail, code = ${code}`)
}
})
return true
},
}
</script>
Result
Tips and Tricks
Understand About Quick Game.
Explore some Quick Game from phone.
Install all the required tools.
Make sure you have configured the adb in the desktop or laptop.
Command to install Quick App loader APK is adb install quickapploader.apk
Enable Game service and account kit.
Conclusion
In this article, we have learnt about creating Quick Game, generating and configuring the SHA-256 fingerprint certificate, Enabling game service and account kit and building HTML5 Quick Game application.
Reference
Quick Game official document
Download tools from here
Beginner: Find the Explanation of Quick Game Part 1
thanks for sharing

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

Practice on Developing a Face Verification Function

Background​Oh how great it is to be able to reset bank details from the comfort of home and avoid all the hassle of going to the bank, queuing up, and proving you are who you say you are.
All these have become true with the help of some tech magic known as face verification, which is perfect for verifying a user's identity remotely. I have been curious about how the tech works, so here it is: I decided to integrate the face verification service from HMS Core ML Kit into a demo app. Below is how I did it.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Development Process​Preparations​1. Make necessary configurations as detailed here.
2. Configure the Maven repository address for the face verification service.
Open the project-level build.gradle file of the Android Studio project.
Add the Maven repository address and AppGallery Connect plugin. Go to allprojects > repositories and configure the Maven repository address for the face verification service.
Code:
allprojects {
repositories {
google()
jcenter()
maven {url 'https://developer.huawei.com/repo/'}
}
}
Go to buildscript > repositories to configure the Maven repository address.
Code:
buildscript {
repositories {
google()
jcenter()
maven {url 'https://developer.huawei.com/repo/'}
}
}
Go to buildscript > dependencies to add the plugin configuration.
Code:
buildscript{
dependencies {
classpath 'com.huawei.agconnect:agcp:1.3.1.300'
}
}
Function Building​1. Create an instance of the face verification analyzer.
Code:
MLFaceVerificationAnalyzer analyzer = MLFaceVerificationAnalyzerFactory.getInstance().getFaceVerificationAnalyzer();
2. Create an MLFrame object via android.graphics.Bitmap. This object is used to set the face verification template image whose format can be JPG, JPEG, PNG, or BMP.
Code:
// Create an MLFrame object.
MLFrame templateFrame = MLFrame.fromBitmap(bitmap);
3. Set the template image. The setting will fail if the template does not contain a face, and the face verification service will use the template set last time.
Code:
List<MLFaceTemplateResult> results = analyzer.setTemplateFace(templateFrame);
for (int i = 0; i < results.size(); i++) {
// Process the result of face detection in the template.
}
4. Use android.graphics.Bitmap to create an MLFrame object that is used to set the image for comparison. The image format can be JPG, JPEG, PNG, or BMP.
Code:
// Create an MLFrame object.
MLFrame compareFrame = MLFrame.fromBitmap(bitmap);
5. Perform face verification by calling the asynchronous or synchronous method. The returned verification result (MLFaceVerificationResult) contains the facial information obtained from the comparison image and the confidence indicating the faces in the comparison image and template image being of the same person.
Asynchronous method:
Code:
Task<List<MLFaceVerificationResult>> task = analyzer.asyncAnalyseFrame(compareFrame);
task.addOnSuccessListener(new OnSuccessListener<List<MLFaceVerificationResult>>() {
@Override
public void onSuccess(List<MLFaceVerificationResult> results) {
// Callback when the verification is successful.
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
// Callback when the verification fails.
}
});
Synchronous method:
Code:
SparseArray<MLFaceVerificationResult> results = analyzer.analyseFrame(compareFrame);
for (int i = 0; i < results.size(); i++) {
// Process the verification result.
}
6. Stop the analyzer and release the resources that it occupies, when verification is complete.
Code:
if (analyzer != null) {
analyzer.stop();
}
This is how the face verification function is built. This kind of tech not only saves hassle, but is great for honing my developer skills.
​References​Face Verification from HMS Core ML Kit
Why Facial Verification is the Biometric Technology for Financial Services in 2022

Categories

Resources