Integrating Ads kit using Flutter (Hybrid development) - Huawei Developers

Introduction
Huawei is providing one of the best HMS Ads kit to advertise their ads via mobile apps. In this way they can reach their target audience more easily and they can measure their efficiency. Using Ads kit we can create high quality and personalized ads in our application.
        
{
"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"
}
Supported Ad Types
1. Splash Ads
2. Banner Ads
3. Interstitial Ads
4. Native Ads
5. Rewarded Ads
6. Roll Ads
7. Express Splash Ads
Flutter setup
 Refer this URL to setup Flutter.
Software Requirements
 1. Android Studio 3.X
2. JDK 1.8 and later
3. SDK Platform 19 and later
4. Gradle 4.6 and later
Steps to integrate service
1. Register as a Developer
2.Create an App
3.Enable required services (Cloud or Device)
4.Integrate HMS Core SDK
5.Apply for SDK Permission
6.Perform App Development
7.Perform pre-release check (Mandatory)
Development Process
Create Application in Android Studio.
1. Create Flutter project.
2. App level gradle dependencies. Choose inside project Android > app > build.gradle
Code:
apply plugin: 'com.android.application'
apply plugin: 'com.huawei.agconnect'
Gradle dependencies
Code:
implementation 'com.huawei.hms:ads-lite:13.4.34.301'
implementation 'com.huawei.hms:ads-consent:3.4.34.301'
implementation 'com.huawei.hms:ads-identifier:3.4.32.300'
implementation 'com.huawei.hms:ads-installreferrer:3.4.32.300'
Root level gradle dependencies
Code:
maven {url 'https://developer.huawei.com/repo/'}
classpath 'com.huawei.agconnect:agcp:1.4.1.300'
Add the below permissions in Android Manifest file.
Code:
<manifest xlmns:android...>
...
<uses-permission android:name="android.permission.INTERNET" />
<application>
</manifest>
3. Add agconnect-services.json into under app directory.
4. Add HMS Ads kit plugin download using below URL.
https://developer.huawei.com/consum...y-V1/flutter-sdk-download-0000001050196675-V1
5. Add downloaded file into outside project directory. Declare plugin path in pubspec.yaml file under dependencies.
Code:
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.0
huawei_ads:
path: ../huawei_ads/
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
assets:
- assets/1.png
- assets/3.png
- assets/5.png
- assets/2.png
- assets/7.png
6. After adding all required plugins click Pub get, automatically it will install latest dependencies.
7. We can check the plugins under External Libraries directory.
8. Open main.dart file to create UI and business logics.
More detials, you can check https://forums.developer.huawei.com/forumPortal/en/topic/0203423861622320018

Related

Earthquake application with Huawei Map and Location kits

Learn how to create a earthquake app that includes the Huawei Map Kit and Location Kit using the Flutter SDK.
{
"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
Hello everyone, In this article, I will make an earthquake application with Flutter. We will make an some APIs provided by the Huawei Map and Location Kit and learn how to use them in an earthquake project.
Huawei Map Kit, provides standard maps as well as UI elements such as markers, shapes, and layers for you to customize maps that better meet service scenarios.
Huawei Location Kit combines the GPS, Wi-Fi, and base station locations to help you quickly obtain precise user locations, build up global positioning capabilities, and reach a wide range of users around the globe.
Configuring The Project
Before you get started, you must register as a HUAWEI developer and complete identity verification on the HUAWEI Developer website. For details, please refer to Register a HUAWEI ID.
Create an app in your project is required in App Gallery Connect in order to communicate with Huawei services.
★ Integrating Your Apps With Huawei HMS Core
Permissions
In order to make your kits work perfectly, you need to add the permissions below in AndroidManifest.xml file.
Code:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
HMS Integration
Check whether the agconnect-services.json file and signature file are successfully added to the android/app directory of the Flutter project.
Add the Maven repository address and AppGallery Connect service dependencies into the android/build.gradle file.
Code:
buildscript {
repositories {
google()
jcenter()
maven { url 'https://developer.huawei.com/repo/' }
}
dependencies {
/*
* <Other dependencies>
*/
classpath 'com.huawei.agconnect:agcp:1.4.1.300'
}
}
Configure the Maven repository address for the HMS Core SDK in allprojects.
Code:
allprojects {
repositories {
google()
jcenter()
maven { url 'https://developer.huawei.com/repo/' }
}
}
Add the apply plugin: ‘com.huawei.agconnect’ line after the apply from: “$flutterRoot/packages/flutter_tools/gradle/flutter.gradle” line.
Code:
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.huawei.agconnect'
Open your app level build.gradle (android/app/build.gradle) file and set minSdkVersion to 19 or higher in defaultConfig. (applicationId must match the package_name entry in the agconnect-services.json file)
Code:
defaultConfig {
applicationId "<package_name>"
minSdkVersion 19
/*
* <Other configurations>
*/
}
Creating Flutter Application
Find your Flutter project’s pubspec.yaml file directory open it and add Huawei Map and Huawei Location Plugins as a dependency. Run the flutter pub get command to integrate the Map & Location Plugins into your project.
There are all plugins in pub.dev with the latest versions. If you have downloaded the package from pub.dev, specify the package in your pubspec.yaml file. Then, run flutter pub get command.
Map Kit Plugin for Flutter
Location Kit Plugin for Flutter
Code:
dependencies:
flutter:
sdk: flutter
http: ^0.12.2
huawei_map: ^4.0.4+300
huawei_location: ^5.0.0+301
We’re done with the integration part! Now, we are ready to make our earthquake application ✓
Make an Earthquake App with Flutter
Create Earthquake Response Data
First of all, we will create an EartquakeResponseData class to access the latest earthquake data. Later, we will call this class with the getData() function.
Additionally, we will use the http package to access the data, so we need to import import ‘package: http / http.dart’ as http; into the detail page.dart class.
More details, you can check https://forums.developer.huawei.com/forumPortal/en/topic/0204423826967890020
Could be useful for some countries.
Very very useful.
Very interesting.
Where are you getting the data for earthQuake and in what format ?

Huawei ML Kit - Image Classification feat. React Native(Cross Platform)

Introduction
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Image Classification is the process where a computer device can analyse and define the image category or class in simple language.
Image Classification can be used in many intelligent services, photo gallery application and to design highly efficient security products and services.
Huawei ML Kit enable developers to use its highly efficient API’s to implement the image classification for their mobile applications.
Huawei ML Kit classifies the elements presents in an image into defined categories such as objects, environment, artwork, animal, etc.
Huawei ML Kit’s Image Classification API’s are available for two different classification modes
On Device
Device based classification API’s analyse and detects the image category by running the on device algorithm and supports over 400 different image categories.
On Cloud
Cloud based classification API’s analyse and detects the image category by running the on cloud algorithm and supports over 12000 different image categories.
Development Overview
We will be focusing on simple Image Classification service from an image using on device API’s
Prerequisite
1. Must have a Huawei Developer Account
2. Must have a Huawei phone with HMS 4.0.0.300 or later
3. React Native environment with Android Studio, Node Js and Visual Studio code.
Major Dependencies
1. React Native CLI : 2.0.1
2. Gradle Version: 6.0.1
3. Gradle Plugin Version: 4.0.1
4. React Native ML Kit SDK : 5.0.0
5. react-native-hms-ml kit gradle dependency
6. AGCP gradle dependency
Software Requirements
1. Java SDK 1.8 or later
2. Android 5.0 or later
Preparation
1. Create a react native project using React Native CLI and open android directory.
2. Download the React Native ML Kit SDK and paste it under Node modules directory of React Native project.
3. Create an app and project in the Huawei AppGallery Connect.
4. Provide the SHA Key and App Package name of the project.
5. Enable the ML API and download the agconnect-services.json file and paste to the app folder of your android folder.
Integration
Add below to build.gradle (project) file, under buildscript/repositories and allprojects/repositories.
Maven {url 'http://developer.huawei.com/repo/'}
Add below to build.gradle (app) file, under dependencies to use the ML kit SDK in your React Native application.
Code:
dependencies{
// Import the SDK.
implementation project(":react-native-hms-ml ")
…
…
implementation 'com.huawei.agconnect:agconnect-core:1.2.1.301'
}
Add below under Settings.Gradle file
Code:
include ':react-native-hms-ml
project(':react-native-hms-ml).projectDir = new File(rootProject.projectDir, '../node_modules/react-native-hms-ml /android')
Add below under MainApplication.java file.
Code:
import com.huawei.hms.rn.ml.HmsMlPackage;
public class MainApplication extends Application implements ReactApplication {
...
@Override
protected List<ReactPackage> getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
//Add following line. Don't forget to add import statement also.
packages.add(new HmsMlPackage());
return packages;
}
...
};
Add below under AndroidManifest.xml file
Code:
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
<meta-data
android:name="com.huawei.hms.ml.DEPENDENCY"
android:value="ocr"/>
</application>
Use case
Huawei ML kit’s Image Classification API provides many different use cases, however we will take very simple gallery image classification as example.
Imageclassification.js
Imageclassification.js is a java script file which we will keep under “src” folder of the project to have the navigation stack from the launch page.
We will re-direct to “Classify” tab from here to showcase the image classification capabilities.
More details, you can check https://forums.developer.huawei.com/forumPortal/en/topic/0203430657683920058

Integrating AR-Engine kit using Flutter (Cross Platform)

Introduction
Augmented Reality is increasing every day in different areas like shopping, Games, Education etc. AR Engine provides a mesh with more than 4,000 vertices and 7,000 triangles to precisely outline face contours, and enhance the overall user experience.
Today I will develop a demo application and try to explain this features and what it provides in more detail.
{
"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"
}
AR Engine Services
Augmented reality (AR) is an interactive experience of a real-world environment where the objects reside in the real world are enhanced by computer-generated perceptual information, sometimes across multiple sensory modalities, including visual, auditory, haptic, somatosensory and olfactory.
It provide basic AR capabilities such as motion tracking, environment tracking, body tracking, and face tracking.
Restrictions
The current version of Huawei AR Engine supports only Huawei devices. So, you need a Huawei phone that supports Huawei AR Engine, you can see the supported devices below.
AR Engine Process
The following figure shows the general process of using the Huawei AR Engine SDK.
        
Flutter setup
Refer this URL to setup Flutter.
Software Requirements
1. Android Studio 3.X
2. JDK 1.8 and later
3. SDK Platform 24 and later
4. Gradle 4.6 and later
5. Ensure that the AR Engine server APK have been downloaded from AppGallery and installed on the device. To do so, search for HUAWEI AR Engine in Huawei AppGallery.
            
Steps to integrate service
1. We need to register as a developer account in AppGallery Connect
2. Create an app by referring to Creating a Project and Creating an App in the Project
3. Set the data storage location based on current location
4. Generating a Signing Certificate Fingerprint.
5. Configuring the Signing Certificate Fingerprint.
6. Get your agconnect-services.json file to the app root directory.
Development Process
Create Application in Android Studio.
1. Create Flutter project.
2. App level gradle dependencies. Choose inside project Android > app > build.gradle.
Code:
apply plugin: 'com.android.application'
apply plugin: 'com.huawei.agconnect'
Root level gradle dependencies
Code:
maven {url 'https://developer.huawei.com/repo/'}
classpath 'com.huawei.agconnect:agcp:1.4.1.300'
Add the below permissions in Android Manifest file.
Code:
<manifest xlmns:android...>
...
<uses-permission android:name="android.permission.CAMERA" />
<application ...
</manifest>
3. Add HMS AR Engine kit plugin download using below URL.
https://developer.huawei.com/consum...y-V1/flutter-sdk-download-0000001059096444-V1
4. On your Flutter project directory find and open your pubspec.yaml file and add library to dependencies to download the package from pub.dev. Or if you downloaded the package from the HUAWEI Developer website, specify the library path on your local device. For both ways, after running pub get command, the plugin will be ready to use.
Code:
name: arDemo
description: A new Flutter application.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
huawei_ar:
path: ../huawei_ar/
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
5. We can check the plugins under External Libraries directory.
6. Open main.dart file to create UI and business logics.
More details, you can check https://forums.developer.huawei.com/forumPortal/en/topic/0202460753111420009

HMS Multi Kit Integration (Extended) in Unity Game Development

Introduction
Huawei provides various services for developers to make ease of development and provides best user experience to end users. In this article, we will be integrating following kits:
Ads Kit
Game services
Analytics Kit
Location Kit
Push Kit
We will learn to integrate above HMS Kits in Unity game development using official plugin. And by integrating in single application gives experience the ease of development and give best user experience and showcases stability of the kits, and how we can use kits efficiently to make users experience the best of it.
Development Overview
You need to install Unity software and I assume that you have prior knowledge about the unity and C#.
Hardware Requirements
A computer (desktop or laptop) running Windows 10.
A Huawei phone (with the USB cable), which is used for debugging.
Software Requirements
Java JDK installation package.
Unity software installed.
Visual Studio/Code installed.
HMS Core (APK) 4.X or later.
Integration Preparations
1. Create a project in AppGallery Connect.
2. Create Unity project.
{
"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. Adding Huawei HMS AGC Services to project.
5. Generate a SHA-256 certificate fingerprint.
To generating SHA-256 certificate fingerprint use below command.
6. Configure the signing certificate fingerprint.
7. Download and save the configuration file.
Add the agconnect-services.json file following dir Assets > Plugins > Android
8. Add the following plugin and dependencies in LaucherTemplate
Code:
apply plugin: 'com.huawei.agconnect'
Code:
implementation 'com.huawei.agconnect:agconnect-core:1.4.1.300'
implementation 'com.huawei.hms:base:5.0.0.301'
implementation 'com.huawei.hms:hwid:5.0.3.301'
implementation 'com.huawei.hms:game:5.0.1.302'
implementation 'com.huawei.hms:push:4.0.1.300'
implementation 'com.huawei.hms:hianalytics:5.0.3.300'
9. Add the following dependencies in MainTemplate.
Code:
implementation 'com.huawei.agconnect:agconnect-core:1.4.1.300'
implementation 'com.huawei.hms:base:5.0.0.301'
implementation 'com.huawei.hms:hwid:5.0.3.301'
implementation 'com.huawei.hms:game:5.0.1.302'
implementation 'com.huawei.hms:hianalytics:5.0.3.300'
implementation 'com.huawei.hms:ads-lite:13.4.29.303'
implementation 'com.huawei.hms:ads-consent:3.4.30.301'
implementation 'com.huawei.hms:push:4.0.1.300'
implementation 'com.huawei.hms:location:5.0.0.301'
10. Add the following dependencies in MainTemplate.
repositories & class path in BaseProjectTemplate.
Code:
maven { url 'https://developer.huawei.com/repo/' }
Code:
classpath 'com.huawei.agconnect:agcp:1.2.1.301'
11. Add Achievement details in AGC > My apps
12. Add LeaderBoard details.
Continue reading..
Tips and Tricks
Add agconnect-services.json file without fail.
Add SHA-256 fingerprint without fail.
Add Achievements and LeaderBoad details before run.
Make sure dependencies added in build files.
Enable location and accept permission to read location.
Conclusion
We have learnt integration of HMS GameService Kit, Ads Kit,Location kit, Push Kit and Analytics kit in Unity. Error code while fetching Player extra information and Event Begin and end.
7006: The account has not been registered in Chinese mainland. In this case, perform bypass and no further action is required.
Thanks for reading, please do like and comment your queries or suggestions.
Read full article
References
Hms game services
HMS Ads Kit
HMS Analytics Kit
HMS Push Kit
Location Kit

Integrating Cloud Functions in a Flutter application

Cloud Functions enables serverless computing through Function as a Service (FaaS) capabilities to simplify app development and O&M. This helps you implement functions more simply and build service capabilities more quickly. The following describes how to integrate Huawei’s AppGallery Connect Cloud Function service in Flutter.
We will create a basic new project as an example but of course, you could make use of a project you already have that's using flutter!
Project Setup​Install the Flutter environment.​Download the Flutter SDK package and decompress the package to any directory.
{
"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"
}
Download the Flutter and Dart plugins in Android Studio.
Enable Huawei Cloud Functions​Create an Android app in AppGallery Connect and enable Cloud Functions for it as detailed in this guide.
Now we can go ahead and create a cloud function as you require it to use this guide to help understand what can be done.
Once you are happy with your function (in this instance it might just be as simple as returning a hello world statement for testing) you can go ahead and create a HTTP trigger that will trigger the function.
Create Flutter Project​Next create your flutter project in android studio (or open your existing project if you already have one!).
Download your agconnect-services.json file from the AppGallery Connect console and add it to your project under the ‘app’ directory
Within the project-level build.gradle file make sure to include the Huawei maven repo and add the agcp package as a dependency.
Code:
buildscript {
repositories {
google()
mavenCentral()
maven { url 'https://developer.huawei.com/repo/' }
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
classpath 'com.huawei.agconnect:agcp:1.6.2.300'
}
}
Next in your app level build.gradle apply the agconnect plugin as so:
Code:
apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.huawei.agconnect'
Then in your pubspec.yaml file add the Cloud Function SDK dependency.
Code:
dependencies:
flutter:
sdk: flutter
agconnect_cloudfunctions: 1.2.0+300
Call the Cloud function​The below code is an example of how you can call a simple cloud function and get the result returned.
Code:
FunctionCallable functionCallable = FunctionCallable("test-\$latest");
Map<String, dynamic> parameters = <String, dynamic>{
'year': _functionTextController.text
};
FunctionResult functionResult = await functionCallable.call(parameters);
Where test-\$latest is the HTTP trigger identifier.
https://devwithzachary.medium.com/?...-------------------post_sidebar--------------
Good Article
Thanks for sharing!!!
Do we need any special permission for cloud function.
Thanks for sharing!

Categories

Resources