Process description of the DeviceVirtualization Engine Application Development Guide - Huawei Developers

1.Device Selection Dialog Box
Any app that uses the HUAWEI DeviceVirtualization Engine must display the following dialog box for users to select capable devices to complete capability continuation.
The design of this dialog box must follow the HUAWEI DeviceVirtualization Engine Third-Party App UX Design Specifications, and DV Engine Icon Resources should be used.
2. Device Compatibility
Currently, DeviceVirtualization Engine supports only Huawei mobile phones. When an app invokes the APIs in DV Engine in an unsupported running environment, or on a Huawei phone running an unsupported EMUI version, the system throws NoClassDefFoundError.
Therefore, apps should check compatibility between the running environment and DV Engine version.
In the following example, CURRENT_KIT_VERSION is the HUAWEI DV Engine version that the app is compatible with. The app needs to record the version, and check whether the DV Engine version on the current mobile phone is the same as the DV Engine version that the app is compatible with. If not, compatibility processing is required.
HTML:
boolean isSupport = true;
try {
// Obtain the running version of DV Kit.
String version = DvKit.getVersion();
if (version.compareTo(CURRENT_KIT_VERSION) < 0) {
// The current DV Kit version does not meet the app running requirements.
isSupport = false;
}
} catch (NoClassDefFoundError e) {
// The current running environment does not support the DV Kit.
isSupport = false;
Log.e(TAG, "DvKit not exist", e);
}
if (isSupport) {
// The current DV Kit version meets the app running requirements.
Intent intent = new Intent(MainActivity.this, DvKitDemoActivity.class);
startActivity(intent);
}
3.Development Process
To use the DV Engine service, you need to declare the permission to use virtual peripherals and the permission required for the app to invoke the corresponding API of the DV Engine service, such as the camera permission, audio permission, and body sensor permission.
When using the DV Engine capabilities, an app needs to apply for different Android permissions accordingly. These permissions need to be declared in the app code. The Android permissions corresponding to different DV Engine capabilities are as follows:
1. Virtual camera permission of DV Engine, which is mandatory for using camera capabilities.
Code:
android.permission.CAMERA
2. Virtual microphone permission of DV Engine, which is mandatory for using microphone capabilities.
Code:
android.permission.RECORD_AUDIO
3.Virtual sensor permission of DV Engine, which is mandatory for using sensor capabilities. The virtual sensors include body_sensor's heart rate monitor, accelerometer, barometer, and gyroscope.
Code:
android.permission.BODY_SENSORS
4. Virtual vibrator permission of DV Engine, which is mandatory for using vibrator capabilities.
Code:
android.permission.VIBRATE
5. Virtual device permission of DV Engine, which is mandatory for using the distributed virtual devices.
Code:
com.huawei.permission.DISTRIBUTED_VIRTUALDEVICE
This permission must be obtained before DV Engine is connected. Otherwise, the distributed virtualization capability cannot be used. You can call the requestPermissions method of Android to dynamically apply for the permission where appropriate in the process, based on the service.
Example:
To use the DV Engine service, you need to declare the permissions to use the camera, audio, and distributed virtual peripherals.
Code:
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="com.huawei.permission.DISTRIBUTED_VIRTUALDEVICE"/>
The basic method is to create a basic DV Engine object, connect the object to the back-end service for initialization, and obtain the VirtualDeviceManager service through the object.
The VirtualDeviceManager service can be used to discover virtualized devices controllable from phones, together with their capabilities, which can be developed to meet service needs.
For example, when the VirtualDeviceManager service detects a TV and returns the display, microphone, speaker, and camera capabilities supported by the TV, the app can then enable the corresponding capabilities as required.
{
"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"
}

Related

Remote Config : Dynamically Change your app’s Behavior

This is originally from HUAWEI Developer Froum
Forum link: https://forums.developer.huawei.com/forumPortal/en/home
{
"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
Remote config is a feature that allows us to alter both the look and feel of our application without the need to publish any updates to the App Gallery. This works by allowing us to define in-app parameters that can be overridden from within the Huawei App Gallery Connect — these parameters can then be activated for either all or a defined selection of users.
This powerful feature gives us a range of new abilities when it comes to immediate updates, temporary changes or testing new features amongst users. Let’s take a dive and learn the what, why and how of Remote Config so we can learn how to use it to benefit both ourselves and our users
Use Cases
1. Releasing new functions by user percentage.
2. Display country/region-specific promotion content.
3. Personalized content recommendation based on Huawei Analytics.
4. Holiday theme adaptation.
Development Process
· Create sample application in android and configure into AGC.
· Enable Remote Configuration API.
· Download agconnect-service.json and add into app directory.
· Add remote config dependencies in the build.gradle file in app directory.
Code:
implementation 'com.huawei.agconnect:agconnect-remoteconfig:1.3.1.300'
· Open AGC select Demo project Growing->Remote Config Now enable Remote Config service
After enabling service, you will get option
· Parameter Management.
· Condition Management.
Parameter Management:
Within Remote Config we define key-value pairs which are known as parameters. These parameters are then used to define the configuration values that are to be used within our app.
· Key — The key is a String used to define the identify for the parameter
· value — The value can be of any other data type and is used to represent the value of our defined parameter.
· After saving parameter management details we can check ,you can add, modify, delete in existing parameters.
Condition Management
Conditions are a collection of rules that we can use to target specific app instances —for example based on gender we can update new changes.
The conditional value itself is also represented as a key-value pair, it’s made up of:
· condition — The condition to be satisfied for the value to be used
§ App version
§ OS version
§ Language
§ Country/Region
§ Audience, etc..
· value — The value to be used if the condition is satisfied
Let’s see code Implementation
· Create Instance for AGConnectConfig
Code:
AGConnectConfig config = AGConnectConfig.getInstance();
· Create config.xml file ,you can set default parameter values before connecting to remote config service.so that your app can run perfectly.
Code:
<?xml version="1.0" encoding="utf-8"?>
<remoteconfig>
<value key="version">1.0</value>
</remoteconfig>
· Call Api to pass default values this will effect immediately.
Code:
config.applyDefault(R.xml.remote_config);
· Fetching parameter values from Remote Configuration
Code:
config.fetch(fetchInterval).addOnSuccessListener(new OnSuccessListener<ConfigValues>() {
@Override
public void onSuccess(ConfigValues configValues) {
config.apply(configValues);
config.getMergedAll();
long remoteVersionCode = config.getValueAsLong("version");
if (currentVersionCode > remoteVersionCode) {
ShowUpdateAlert();
}
Toast.makeText(getBaseContext(), "RemoteVersionCode: "+String.valueOf(remoteVersionCode), Toast.LENGTH_LONG).show();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
Toast.makeText(getBaseContext(), "Fetch Fail", Toast.LENGTH_LONG).show();
}
});
This is not the end. For full content, you can visit HUAWEI Developer Forum.​

Remote Configuration — A/B Testing | Use And Analyze New Features Without Any Update

More information like this, you can visit HUAWEI Developer Forum​
Original link: https://forums.developer.huawei.com/forumPortal/en/topicview?tid=0201332997357290022&fid=0101187876626530001
{
"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"
}
Hello everyone. In this article, I would like to talk about Remote Configuration — A/B Testing. What are they and where are they used? I want to start with these.
Remote Configuration
With the service, you can make changes in the behavior and appearance of your application without any updates. This process is managed by determining various parameters on the Console.
Use Cases:
Displaying the Language by Country/Region
Displaying Different Content to Different Users
Adapting the App Theme by Time
Releasing New Functions
Configurations
Go to Growing> Remote Configuration. Click Enable now to enable Remote Configuration.
Add the Remote Configuration dependencies in the build.gradle file in the app directory.
Code:
implementation 'com.huawei.agconnect:agconnect-remoteconfig:1.4.0.300'
Development
I have prepared a demo app to explain this service better. I’ll talk about it step by step.
First, I set the parameter using the Parameter Management tab in the Remote Config tab.
Then I determined the condition in the Condition Management tab and defined it in the parameter tab.
After the integration process on AGC is completed, you can start writing code on the application. In the code part, you must first specify the parameter you defined in AGC. You can do this by using the “Map” object or “XML”. I used XML.
Code:
override fun onCreate(savedInstanceState: Bundle?)
{
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
/*
- Using a Map object
val mapDefault = mapOf("language" to "other",
"key2" to "val2",
"key3" to "val3",
"key4" to "val4")
- Using an XML resource file
<?xml version="1.0" encoding="utf-8"?>
<remoteconfig>
<value key="language">other</value>
</remoteconfig>
*/
val agConnectConfig = AGConnectConfig.getInstance()
agConnectConfig.applyDefault(R.xml.remote_config)
remoteButton = findViewById(R.id.remote)
remoteButton?.setOnClickListener {
agConnectConfig.fetch(0).addOnSuccessListener {
agConnectConfig.apply(it)
val languageResponse = agConnectConfig.getValueAsString("language")
Toast.makeText(this, languageResponse, Toast.LENGTH_LONG).show()
if (languageResponse == "en"){
showUpdateAlert("Language is English")
}
else if(languageResponse == "other"){
showUpdateAlert("Language is not English")
}
}.addOnFailureListener {
// fail fetching from remote config
it.printStackTrace()
}
}
}
After writing the code, you can test the Remote Configuration by making changes on the device according to the parameter.
A/B Testing
You can use the service to create one or more A/B tests engaging different user groups to compare your variants of app UI design, copywriting, product functions, or marketing activities for performance metrics and find the best one that meets user requirements.
Use Cases:
App UI Design Testing
App Copywriting Testing
App Function Testing
Configurations
Go to Growing > A/B Testing. Click Enable now in the upper right corner.
After the service is enabled, the page shown in the following figure is displayed.
Notifications Experiment:
When you want to send notifications to existing users, you can use the A/B Testing to find out which user is affected by what type of notification.
Remote Configuration Experiment:
You can use A/B Testing to determine specific behaviors for specific user groups in your application or if you want to learn how it affects users before updating your application.
Development
I used the Remote Configuration Experiment. I’ll try to explain the steps here.
Firstly, you need to access Analytics Kit to obtain the target experiment users and experiment data, and generate experiment reports.
Enable Analytics Kit
Add the following code to the build.gradle file in the app directory
Code:
implementation 'com.huawei.hms:hianalytics:4.0.2.300'
Create User Attributes in this way to use the User Attributes condition.
Create a condition on the Remote Configuration tab.
Use Conditions to create your parameter.
Then you will see a four-step screen when you press the Create Remote Configuration Experiment button on the A/B Testing tab.
Set the basic information of the test.
Specify the conditions for finding the target users in this step.
In this step, select your Remote Configuration parameter.
You can select the indicators you want to see as a result of the test. A maximum of 5 options can be selected.
After these steps, you can start writing your code based on the conditions in your application.
Code:
override fun onCreate(savedInstanceState: Bundle?)
{
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
/*
- Using a Map object
val mapDefault = mapOf("ABTest" to "c",
"key2" to "val2",
"key3" to "val3",
"key4" to "val4")
- Using an XML resource file
<?xml version="1.0" encoding="utf-8"?>
<remoteconfig>
<value key="ABTest">c</value>
</remoteconfig>
*/
val agConnectConfig = AGConnectConfig.getInstance()
agConnectConfig.applyDefault(R.xml.remote_config)
remoteButton = findViewById(R.id.remote)
remoteButton?.setOnClickListener {
agConnectConfig.fetch(0).addOnSuccessListener {
agConnectConfig.apply(it)
val abTestResponse = agConnectConfig.getValueAsString("ABTest")
if (abTestResponse == "a"){
showUpdateAlert("abTestResponse = A ")
}
else if(abTestResponse == "b"){
showUpdateAlert("abTestResponse = B ")
}
}.addOnFailureListener {
// fail fetching from remote config
it.printStackTrace()
}
}
}
Finally, you need to start your test on the A/B Testing screen. Sufficient data must be collected to obtain the test result.
I’d like to add the screenshots I took while I was doing the test.
Conclusion
By using these two services, you can diversify your application according to your users, thus increasing the interaction. Moreover, without updating the application.
I hope this article was useful.
References
Remote Configuration
A/B Testing
Nice article
Is huawei AB testing better than google firebase AB testing
riteshchanchal said:
Is huawei AB testing better than google firebase AB testing
Click to expand...
Click to collapse
For me, huawei's is better in some aspects. But I actually suggest you have a try by yourself.

App Development made easy with Huawei Dynamic Ability

Overview
Android App Bundle (.aab) is a new publishing format introduced by Android. A few out of many benefits of using app bundle are dynamic ability, automatic multi-APK distribution, smaller APK size and dynamic feature modules.
AppGallery uses your app bundle to generate and serve optimized APKs for each user’s device configuration, so they download only the code and resources they need to run your app. For example, a user should not get x86 libs if the device architecture is armeabi. Also, users should not get other resources like strings and drawables they are not using.
Introduction
Dynamic Ability modules allow you to separate certain features and resources from the base module of your app.
HUAWEI AppGallery provides a sub-app bundle that adapts only to the user's device type, thereby reducing network data and device storage space, with which the same service functions can be provided.
Dynamic Ability initial app download is smaller for all users. Developers can customize how and when that feature is downloaded onto devices running Android 5.0 (API level 21) or higher. It gives freedom to integrate large 3rd party libraries (< 150MB) on demand.
{
"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"
}
Dynamic Ability with split APKs
Split APKs are very similar to regular APKs. They can include compiled DEX bytecode, resources, and an Android manifest. However, the Android platform is able to treat multiple installed split APKs as a single app. The benefit of split APKs is to break up a monolithic APK into smaller, discrete packages that are installed on a user’s device as required.
Base APK: This APK contains code and resources that all other split APKs can access and provides the basic functionality for your app.
Configuration APKs: Each of these APKs includes native libraries and resources for a specific screen density, CPU architecture, or language. That is, they are downloaded and installed along with the APK they provide code and resources for.
Dynamic Feature APKs: Each of these APKs contains code and resources for a feature of your app that is not required when your app is first installed. That is, using the Dynamic ability SDK, dynamic APKs may be installed on-demand after the base APK is installed on the device to provide additional functionality to the user.
Prerequisite
1. A computer with Android Studio installed and able to access the Internet
2. Huawei phone
3. Java JDK (1.8 or later)
4. Android API (level 21 or higher)
5. Android Studio (3.2 or later)
Integration process
1. Open the build.gradle file in the root directory of your Android Studio project.
Code:
dependencies {
implementation 'com.huawei.hms:dynamicability:1.0.11.302' ...
}
2. Add the following lines in the build.gradle file in Base App. In the file, the Android closure contains the following configuration.
Code:
android {
// Ignore irrelevant configurations.
// Base App is associated with Dynamic Feature Module.
dynamicFeatures = [":demofeature"]
}
3. Add the following lines in the build.gradle file in Dynamic Feature Module. In the file, the dependencies closure contains the following configuration.
Code:
dependencies {
// Ignore irrelevant configurations.
// The module depends on Base App.
implementation project(':app')
}
3. Add the following lines in the build.gradle file in Dynamic Feature Module. In the file, the dependencies closure contains the following configuration.
Code:
dependencies {
// Ignore irrelevant configurations.
// The module depends on Base App.
implementation project(':app')
}
4. Set Application for Base App in the project, override the attachBaseContext() method, and add the SDK startup code.
Code:
public class MyApplication extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
// Start the Dynamic Ability SDK.
FeatureCompat.install(base);
}
}
5. Add the following configuration to the activity in the feature.
Code:
@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(newBase);
FeatureCompat.install(newBase);
}
More details, you can visit https://forums.developer.huawei.com/forumPortal/en/topic/0204411536738730208

Improving app security with HMS Safety Detect

{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
These days mobile devices are part of our life. We do many operations from our mobile phones such as making payment, logging in to social media accounts, checking our bank accounts.
These are the operations which need high security level. If our device will have malicious apps or something like that, our accounts will have trouble and we may suffer many financial and moral damages.
In this article, I will talk about how to improve app security by using HMS Safety Detect Kit.
To do that, I have developed a simple secure web browser app. Because in web browsers, we can use bank websites, we can login to our social media, we can make some payment and use our credit/bank card information. We wouldn’t like to our information to be stolen.
Code:
def koinVersion = "2.2.0-rc-4"
dependencies {
....
// Koin for Android
implementation "org.koin:koin-android:$koinVersion"
// Koin Android Scope feature
implementation "org.koin:koin-android-scope:$koinVersion"
// Koin Android ViewModel feature
implementation "org.koin:koin-android-viewmodel:$koinVersion"
}
After we have implemented the Koin dependencies, we need to create our modules which we will add in our application class.
We will get necessary objects with the help of these modules. I prefer to define different module files for different works.
Code:
val applicationModule = module {
single(named("appContext")){ androidApplication().applicationContext }
factory { HmsHelper() }
factory { SystemHelper() }
}
Code:
val dataModule = module {
factory<ErrorItem>(named("HmsNotAvailable")) { ErrorItem(
icon = ContextCompat.getDrawable(get(named("appContext")), R.drawable.huawei)!!,
title = androidContext().getString(R.string.hms_not_available),
message = androidContext().getString(R.string.download_hms_core)) }
factory<ErrorItem>(named("DeviceNotSecure")) { ErrorItem(
icon = ContextCompat.getDrawable(get(named("appContext")), R.drawable.ic_device_not_secure)!!,
title = androidContext().getString(R.string.device_not_secure),
message = androidContext().getString(R.string.device_not_secure_message)) }
factory<ErrorItem>(named("MaliciousApps")) { ErrorItem(
icon = ContextCompat.getDrawable(get(named("appContext")), R.drawable.ic_malicious_apps)!!,
title = androidContext().getString(R.string.device_not_secure),
message = androidContext().getString(R.string.malicious_apps_message)) }
}
App Preparations
I use Koin framework for dependency injection in my application.
To use Koin Framework in our application, we should add 3 dependencies to our app. In the above, you can find dependencies which you need to add in app-level build.gradle file.
Code:
val viewModelModule = module {
viewModel { SplashViewModel() }
}
After we have defined our modules, we need to setup Koin in our application class.
While starting Koin, we should add our modules which we have defined above, and if we want to use app context, we should androidContext value.
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.berkberber.hms_securewebbrowser">
....
<application
android:name=".SecureWebBrowserApp"
....
>
....
</application>
</manifest>
Code:
class SecureWebBrowserApp: Application(){
override fun onCreate() {
super.onCreate()
setup()
}
private fun setupKoin(){
startKoin {
androidContext([email protected])
modules(
applicationModule,
viewModelModule,
dataModule
)
}
}
private fun setup(){
setupKoin()
}
}
To get more information about app and to see how I used other things such as Navigation Component, MVVM, and etc. you can visit my GitHub repository.
HMS Safety Detect
Safety Detect Kit helps us to improve the security level of our apps. There are 5 different APIs we can use with HMS Safety Detect Kit.
SysIntegrity API: Helps us to check device security. We can determine that device has been rooted or has not.
AppsCheck API: Helps us to determine and list malicious apps which have installed to device.
URLCheck API: Helps us check whether websites are safe.
UserDetect API: Helps us to determine that user is fake or is not.
WifiDetect API: Helps us to check whether Wi-Fi which the device has connected is secure.
Note: UserDetect API is available outside of Chinese mainland. WifiDetect API is available only in the Chinese mainland.
In this article, I have been focused on app security. So, I used SysIntegrity API and AppsCheck API and I will give you informations about these APIs.
Checking is HMS available on device (optional)
We will use Safety Detect Kit in our application. Safety Detect Kit requires HMS Core to be installed on the device.
We don’t have to make this control, but if device doesn’t have HMS, we can’t use HMS Safety Detect Kit. That’s why I recommend you to check HMS Core availability on device and if device doesn’t have HMS, it is better to show an error screen to user.
To check HMS availability we need to add base HMS dependency to our app-level build.gradle file.
To check that device has HMS support or has not, we can write very basic function called as isHmsAvailable().
More details, you can check https://forums.developer.huawei.com/forumPortal/en/topic/0204429014247900019

Smart Shopping Cart using Scan Kit (Native iOS Swift)

{
"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"
}
Article Introduction
In this article we will show how to integrate Huawei Scan Kit in iOS using native language (swift) and barcode lookup APIs to search and add items with information in your list. The use case has been created to make Smart Shopping Cart with HMS open capabilities.
Huawei Scan Kit
Huawei Scan Kit supports 13 mainstream formats including QR Code, Data Matrix, PDF417, Aztec, EAN-8, EAN-13, UPC-A, UPC-E, Codabar, Code 39, Code 93, Code 128, and ITF. It detects barcodes despite low visibility, glare, damage, distortion, or blur. It also supports Auto Zoom into small and distant barcodes. It can easily processes up to 5 barcodes simultaneously.
Scan Kit can be called in three ways, from which you can choose as needed.
For this article, we implemented Default View for iOS with native Swift language. In Default View mode, Scan Kit scans barcodes using the camera or from images in the album, and also provides a complete scanning UI that can be directly used. You do not need to worry about designing a UI as Scan Kit provides one.
Pre-Requisites
Before getting started, following are the requirements:
Xcode (During this tutorial, we used latest version 12.3)
iOS 9.0 or later (Scan Kit supports iOS 9.0 and above)
Apple Developer Account
iOS device for testing
Development
Following are the major steps of development for this article:
Step 1: Importing the SDK in Pod Mode
1.1: Check whether Cocoapods has been installed:
gem -v
If not, run the following commands to install Cocoapods:
Code:
sudo gem install cocoapods
pod setup
1.2: Run the pod init command in the root directory of the Xcode project and add the current version number to the generated Podfile file.
pod 'ScanKitFrameWork', '~> 1.0.2.300' # Huawei Scan Kit dependency
pod 'Alamofire', '~> 5.2' # Optional: Swift Network call lib dependency
pod 'AlamofireImage', '~> 4.1' # Optional: Swift Image loading lib dependency
pod 'SwiftyJSON', '~> 4.0' # Optional: Swift JSON parsing lib dependency
pod "TTGSnackbar" # Optional: Swift Snackbar lib dependency
pod 'lottie-ios' # Optional: Swift Lottie animation lib dependency
1.3: Run the following command in the same directory of the Podfile file to integrate the HMS Core Scan SDK:
pod install
If you have used Cocoapods, run the following command to update Cocoapods:
pod update
1.4: After the execution is successful, open the project directory, find the .xcworkspace file, and execute it.
Step 2: Assigning Permissions
You need to assign permissions required by your app to call Scan Kit.
To scan barcodes using the camera, you need to add Camera Usage Description (camera permission).
To scan barcodes from images in the album, you need to add Photo Library Usage Description (image read permission).
Open the info.plist file and add the following content:
Step 3: Building Layout
We used Auto Layout. Auto Layout defines your user interface using a series of constraints. Constraints typically represent a relationship between two views. Auto Layout then calculates the size and location of each view based on these constraints. This produces layouts that dynamically respond to both internal and external changes.
In this article, we also used Lottie animation for empty cart list and for the searching animation when user scan barcodes.
Code:
// This extension is responsible to manage all the lottie animation methods
extension HomeViewController {
func setDefaultAnimation(){
if(self.addedItems.count > 0){
showResults()
} else {
noItemFound()
}
}
func noItemFound(){
DispatchQueue.main.async {
self.homeTableView.isHidden = true
self.animationView.isHidden = false
self.animationView.animation = Animation.named("empty_view")
self.animationView.contentMode = .scaleAspectFit
self.animationView.loopMode = .loop
self.animationView.animationSpeed = 1.5
self.animationView.play()
}
}
func showLoading(){
DispatchQueue.main.async {
self.homeTableView.isHidden = true
self.animationView.isHidden = false
self.animationView.animation = Animation.named("not_found")
self.animationView.contentMode = .scaleAspectFit
self.animationView.loopMode = .loop
self.animationView.animationSpeed = 1.5
self.animationView.play()
}
}
func showResults(){
DispatchQueue.main.async {
self.homeTableView.isHidden = false
self.animationView.isHidden = true
}
}
}
More information, you can check https://forums.developer.huawei.com/forumPortal/en/topic/0203446609479290092
It will support all languages ?
Very nice and useful for many applications with an online database.
how can i use customised API in the application?

Categories

Resources