DEV Community

HMS Community
HMS Community

Posted on

Expert: Courier App MVVM Jetpack (HMS CloudDB Kit) in Android using Kotlin- Part-3

**

Overview

**
In this article, I will create a Courier android application using Kotlin in which I will integrate HMS Core kits such as HMS Account, AuthService, Push and Cloud DB Kit.
We have integrated HMS Account and AuthService Kit in part-1 and Client Push Notification Using HMS Push Kit in Part-2 of this series. Kindly go through the link below-
Part-1 https://forums.developer.huawei.com/forumPortal/en/topic/0202841957497640128

Part-2 https://forums.developer.huawei.com/forumPortal/en/topic/0201847982965230092
App will make use of android MVVM clean architecture using Jetpack components such as DataBinding, AndroidViewModel, Observer, LiveData and much more.
In this article, we are going to implement DataBinding using Observable pattern.
**

Huawei Cloud DB Kit Introduction

**
Huawei Cloud DB is a device-cloud synergy database product that enables seamless data synchronization between the device and cloud and between devices, and supports offline application operations, helping you quickly develop device-cloud and multi-device synergy applications.
**

Prerequisite

**
1.Huawei Phone EMUI 3.0 or later.
2.Non-Huawei phones Android 4.4 or later (API level 19 or higher).
3.HMS Core APK 4.0.0.300 or later
4.Android Studio
5.AppGallery Account
**

App Gallery Integration process

**
1.Sign In and Create or Choose a project on AppGallery Connect portal.
2.Navigate to Project settings and download the configuration file.
3.Navigate to General Information, and then provide Data Storage location.
4.Navigate to My Projects > Project Settings > Build > Cloud DB, and click Enable now.
5.Click Add
6.Click Export, select Java, android and Package Name, and click OK.
**

App Development

**
Add Required Dependencies:
•Launch Android studio and create a new project. Once the project is ready.
•Navigate to the Gradle scripts folder and open build.gradle (module: app).Add following dependency for HMS Cloud DB Kits.

implementation 'com.huawei.agconnect:agconnect-cloud-database:1.5.0.300'
    implementation "com.huawei.agconnect:agconnect-auth-huawei:1.6.0.300"
    implementation 'com.huawei.agconnect:agconnect-auth:1.5.0.300'
Enter fullscreen mode Exit fullscreen mode

•Navigate to the Gradle scripts folder and open build.gradle (project: app).

 ext.kotlin_version = "1.4.21"
    repositories {
        google()
        jcenter()
        maven {url 'https://developer.huawei.com/repo/'}
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.0.1"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.huawei.agconnect:agcp:1.4.2.300'
Enter fullscreen mode Exit fullscreen mode

**

Code Implementation

**
•Created following package model, clouddb, viewmodel.
Model: In your primary folder, create a new package and name it model.
CloudInfo.java:

package com.hms.corrierapp.clouddb;

import com.huawei.agconnect.cloud.database.CloudDBZoneObject;
import com.huawei.agconnect.cloud.database.annotations.DefaultValue;
import com.huawei.agconnect.cloud.database.annotations.EntireEncrypted;
import com.huawei.agconnect.cloud.database.annotations.Indexes;
import com.huawei.agconnect.cloud.database.annotations.NotNull;
import com.huawei.agconnect.cloud.database.annotations.PrimaryKeys;

@PrimaryKeys({"CourierID"})
@Indexes({"ID:CourierID"})
public final class CourierInfo extends CloudDBZoneObject {
    private Integer CourierID;

    @NotNull
    @DefaultValue(stringValue = "Courier Name")
    private String CourierName;

    @DefaultValue(stringValue = "Desc")
    private String Desc;

    @EntireEncrypted(isEncrypted = true)
    private String FromAdress;

    @EntireEncrypted(isEncrypted = true)
    private String ToAddress;

    public CourierInfo() {
        super(CourierInfo.class);
        this.CourierName = "Courier Name";
        this.Desc = "Desc";
    }

    public Integer getCourierID() {
        return CourierID;
    }

    public void setCourierID(Integer CourierID) {
        this.CourierID = CourierID;
    }

    public String getCourierName() {
        return CourierName;
    }

    public void setCourierName(String CourierName) {
        this.CourierName = CourierName;
    }

    public String getDesc() {
        return Desc;
    }

    public void setDesc(String Desc) {
        this.Desc = Desc;
    }

    public String getFromAdress() {
        return FromAdress;
    }

    public void setFromAdress(String FromAdress) {
        this.FromAdress = FromAdress;
    }

    public String getToAddress() {
        return ToAddress;
    }

    public void setToAddress(String ToAddress) {
        this.ToAddress = ToAddress;
    }

}


Enter fullscreen mode Exit fullscreen mode

ObjectTypeInfoHelper.java:

package com.hms.corrierapp.clouddb;

import com.huawei.agconnect.cloud.database.CloudDBZoneObject;
import com.huawei.agconnect.cloud.database.ObjectTypeInfo;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public final class ObjectTypeInfoHelper {
    private static final int FORMAT_VERSION = 2;
    private static final int OBJECT_TYPE_VERSION = 1;

    public static ObjectTypeInfo getObjectTypeInfo() {
        ObjectTypeInfo objectTypeInfo = new ObjectTypeInfo();
        objectTypeInfo.setFormatVersion(FORMAT_VERSION);
        objectTypeInfo.setObjectTypeVersion(OBJECT_TYPE_VERSION);
        List<Class<? extends CloudDBZoneObject>> objectTypeList = new ArrayList<>();
        Collections.addAll(objectTypeList, CourierInfo.class);
        objectTypeInfo.setObjectTypes(objectTypeList);
        return objectTypeInfo;
    }
}


Enter fullscreen mode Exit fullscreen mode

**

App Build Result

**
Image description
Image description

**

Tips and Tricks

**
Identity Kit displays the HUAWEI ID registration or sign-in page first. The user can use the functions provided by Identity Kit only after signing in using a registered HUAWEI ID.
Make sure you have added SHA-256 fingerprint without fail.
Set minSDK version to 24 or later, otherwise you will get AndriodManifest merge issue.
**

Conclusion

**
In this article, we have learned how to integrate Huawei ID, Push and Cloud DB Kit in Android application. After completely read this article user can easily implement Huawei ID and Client Side Push Notification and submit courier information on Cloud DB in the Courier android application using Kotlin.
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/consumer/en/doc/development/HMSCore-Guides/introduction-0000001050048870
https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/service-introduction-0000001050040060
https://developer.huawei.com/consumer/en/doc/development/AppGallery-connect-Guides/agc-clouddb-introduction-0000001054212760
Cloud DB Kit Training Video:
https://developer.huawei.com/consumer/en/training/course/video/101628259491513909

Top comments (10)

Collapse
 
colleen_camacho_ef74db930 profile image
colleen camacho

After completely reading this article can i easily implement Huawei ID and Client Side Push Notification and submit courier information on Cloud DB in the Courier android application using Kotlin? I make the same code as udaan courier tracking can you please help me with it.

Collapse
 
expressmbs18 profile image
Express MBS

"Crafting a Courier android application with Kotlin is as precise and efficient as the services offered by Express Medical Billing Services. Just as the article seamlessly integrates HMS Core kits, Express MBS provides a seamless integration of billing solutions. The precision in using HMS Account and AuthService Kit reflects the attention to detail mirrored in Express Medical Billing Services. For a streamlined healthcare revenue cycle, much like a well-crafted Courier app, trust Express MBS to deliver excellence in medical billing services."

Collapse
 
questmbs753 profile image
Quest MBS

As the article unfolds the integration of HMS Core kits for a Courier android application, I'm reminded of the streamlined efficiency that Quest Medical Billing Services brings to the healthcare billing landscape. Just like the precision needed in integrating HMS Account and AuthService Kit, Quest MBS ensures accuracy and efficiency in medical billing processes. The commitment to excellence in client push notifications aligns with Quest MBS's dedication to providing reliable and comprehensive billing solutions. For a seamless journey in both app development and medical billing, Quest Medical Billing Services is the trusted partner.

Collapse
 
expressmbs18 profile image
Express MBS

"Crafting a Courier android application with Kotlin is as precise and efficient as the services offered by Express Medical Billing Services. Just as the article seamlessly integrates HMS Core kits, Express MBS provides a seamless integration of billing solutions. The precision in using HMS Account and AuthService Kit reflects the attention to detail mirrored in Express Medical Billing Services. For a streamlined healthcare revenue cycle, much like a well-crafted Courier app, trust Express MBS to deliver excellence in medical billing services."

Collapse
 
expressmbs18 profile image
Express MBS

"Crafting a Courier android application with Kotlin is as precise and efficient as the services offered by Express Medical Billing Services. Just as the article seamlessly integrates HMS Core kits, Express MBS provides a seamless integration of billing solutions. The precision in using HMS Account and AuthService Kit reflects the attention to detail mirrored in Express Medical Billing Services. For a streamlined healthcare revenue cycle, much like a well-crafted Courier app, trust Express MBS to deliver excellence in medical billing services."

Collapse
 
lonzobrown1 profile image
Lonzo Brown • Edited

I see a website they are working on courier tracking how I make the same code as J&T tracking Malaysia can you please help me with it.

Collapse
 
dramanic profile image
corel Roemer

I see a website they are working on product reviews how I make the same code as steam genarator irons can you please help me with it.

Collapse
 
russkulas profile image
Russ Kulas

I am see a website that are working on Beds in UK I want to make some code as dream gold beds will you provide me it.

Collapse
 
cynthiagcolton profile image
CynthiaGColton

I see a website they are working on product reviews how I make the same code as square vs clover can you please help me with it.

Collapse
 
russkulas profile image
Russ Kulas • Edited

I am see a website that are working on Health services in Pakistan I want to make some code as Rapidhms will you provide me it.