[Huawei Developers] Freemind R:
More information like this, you can visit HUAWEI Developer Forum​

This article is based on Nearby Chat. We will create a new application that provides the chat with nearby people without the internet with the help of Nearby Kit and we can share our current location in latitude and longitude.

We are going to integrate the following kits in this application.

1) Nearby Kit

2) Awareness Kit

3) Scan Kit

Prerequisite

1) Must have a Huawei Developer Account.

2) Must have a Huawei phone with HMS 4.0.0.300 or later.

3) Must have a laptop or desktop with Android Studio, JDK 1.8, SDK platform 26 and Gradle 4.6 installed.

Things Need To Be Done

1) Create a project in android studio.

2) Create a project in the Huawei AppGallery connect.

3) Enable Nearby, Awareness, and Scan kit setting in Manage APIs section.

4) Provide storage location.

5) After completing all the above points we need to download the agconnect-services.json from App Information Section. Copy and paste the Json file in the app folder of the android project.

6) Enter the maven url inside the repositories of buildscript and allprojects (project build.gradle file).

7) Add dependencies inside the app module and Sync Project.

8) Start development with kit integration inside the application.

9) Launch the application.

Create a project in Android Studio

Open your android studio and create a new project, Choose No Activity then click on Next

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200814134945.86787044420065614623782341353886:50510826022734:2800:58437DA10A09C9160E3FABE985767CF3697266E85E71B45001A38749680BE8F2.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200814134945.86787044420065614623782341353886:50510826022734:2800:58437DA10A09C9160E3FABE985767CF3697266E85E71B45001A38749680BE8F2.png[/IMG]

Provide your application name, package, and project location then click on Finish.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200814135013.12091817749002045168232549360473:50510826022734:2800:4B080E501BB2539C5BA59DE6B4E6A1657D9075632EAC586DF13E53DCF37F19AD.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200814135013.12091817749002045168232549360473:50510826022734:2800:4B080E501BB2539C5BA59DE6B4E6A1657D9075632EAC586DF13E53DCF37F19AD.png[/IMG]

Create a project on AppGalleryConnect portal

1. Open AppGalleryConnect portal and choose My projects

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200814135045.79050220545020081192103251501929:50510826022734:2800:DDE460242A60A534772ACD0825DF72653F686F11EFE92AC48F7057DED379F67F.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200814135045.79050220545020081192103251501929:50510826022734:2800:DDE460242A60A534772ACD0825DF72653F686F11EFE92AC48F7057DED379F67F.png[/IMG]

2. Click on Add project and provide your project’s details

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200814135130.94404122884970037448166536022201:50510826022734:2800:63EB476BDB1F614C54C74A15AABDA4036897F7064CA52C37BD893D206DB064C3.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200814135130.94404122884970037448166536022201:50510826022734:2800:63EB476BDB1F614C54C74A15AABDA4036897F7064CA52C37BD893D206DB064C3.png[/IMG]

3. Provide your project name and click Ok

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200814135156.62346824316766003237497884665773:50510826022734:2800:57F7F5A7B265D7825202B2271E8F8F36C1173598C5A098F0E9F6F0E91695A90E.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200814135156.62346824316766003237497884665773:50510826022734:2800:57F7F5A7B265D7825202B2271E8F8F36C1173598C5A098F0E9F6F0E91695A90E.png[/IMG]

Provide storage location

Navigate to General Information then provide Data Storage location.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200814135242.29146901813799558855961125158647:50510826022734:2800:0D8155825CA73F549693E2B04BBA320E191283BA5FD3E5FCA732503F0F6E2D43.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200814135242.29146901813799558855961125158647:50510826022734:2800:0D8155825CA73F549693E2B04BBA320E191283BA5FD3E5FCA732503F0F6E2D43.png[/IMG]

Enable Nearby, Awareness, and Scan kit setting in Manage APIs section

Navigate to Manage APIs and enable APIs which require by application

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200814135316.94368856697914816665745406257362:50510826022734:2800:EA99F4D24B3D8CB0B0BAEF0E69784F151C880C3384B279123B0D2E9B183B7CDA.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200814135316.94368856697914816665745406257362:50510826022734:2800:EA99F4D24B3D8CB0B0BAEF0E69784F151C880C3384B279123B0D2E9B183B7CDA.png[/IMG]

After completing all the above points we need to download the agconnect-services.json

Navigate to General information then download the agconnect-services.json file

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200814135400.47584092469046798056772701953688:50510826022734:2800:B9B7BAC0E8E5DB960F84372E1BA370A9F6E050A03D27367D0316A774FD86AEF4.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200814135400.47584092469046798056772701953688:50510826022734:2800:B9B7BAC0E8E5DB960F84372E1BA370A9F6E050A03D27367D0316A774FD86AEF4.png[/IMG]

Add agconnect-services.json file into your project

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200814135434.80630036635703534525481851708351:50510826022734:2800:73CD845A0C52F13647AA9DF363BDE852076DFC273F98767306FBF65F620ECA02.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200814135434.80630036635703534525481851708351:50510826022734:2800:73CD845A0C52F13647AA9DF363BDE852076DFC273F98767306FBF65F620ECA02.png[/IMG]

Enter the maven url inside the repositories of buildscript and allprojects (project build.gradle file)

Add maven url and add following AppGalleryConnect class path.

buildscript {

repositories {
google()
jcenter()
maven {url 'https://developer.huawei.com/repo/'}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
classpath 'com.huawei.agconnect:agcp:1.3.1.300'

}
}

allprojects {
repositories {
google()
jcenter()
maven {url 'https://developer.huawei.com/repo/'}
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

Add dependencies inside the app module and Sync Project

Add the following dependencies for kit specific in app module based gradle file

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

// Awareness Kit
implementation 'com.huawei.hms:awareness:1.0.6.300'

//Nearby Kit
implementation 'com.huawei.hms:nearby:4.0.4.300'

//Scan Kit
implementation "com.huawei.hms:scan:1.2.0.301"

}

Start development with kit integration inside the application

We have created the following package inside the project

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200814135512.45805301107752332152203191603283:50510826022734:2800:3D2527EB164F28269C4B92B6574B0348DADD7D53AFBF309CB5B7973DB400BE33.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200814135512.45805301107752332152203191603283:50510826022734:2800:3D2527EB164F28269C4B92B6574B0348DADD7D53AFBF309CB5B7973DB400BE33.png[/IMG]

Awareness

We have handled all the operations in this package which is related to awareness kit. We have created LocationAwarenessActivity which implements location-awareness api.

getLocation() method provides accurate latitude and longitude.

private void getLocation() {
Awareness.getCaptureClient(this).getLocation()
.addOnSuccessListener(new OnSuccessListener() {
@Override
public void onSuccess(LocationResponse locationResponse) {
Location location = locationResponse.getLocation();
Utils.setHomeLatitude(location.getLatitude());
Utils.setHomeLongitude(location.getLongitude());
location_details_capture.setText("Capture Your Location
Longitude:" + location.getLongitude()
+ "
Latitude:" + location.getLatitude());

}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
location_details_capture.setText("Failed to get the location.");
}
});
}

This is not the end. For full content, you can visit https://forums.developer.huawei.com/forumPortal/en/topicview?tid=0201327967934830047&fid=0101188387844930001