[Huawei Developers] Freemind R:
More articles like this, you can visit HUAWEI Developer Forum and Medium.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200610060136.17559478831923220536215973422938:50510618025057:2800:6C996E276C70FD1756AE12972E525ECDB7C51531653C065518FB8599C84A4046.jpg"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200610060136.17559478831923220536215973422938:50510618025057:2800:6C996E276C70FD1756AE12972E525ECDB7C51531653C065518FB8599C84A4046.jpg[/IMG]​

In this article, we will learn how to implement Huawei Share Kit in the android project.

Huawei Share Kit provides an easy interface to use so that it can share images, videos, and docs, etc. It delivers stable file transfer speeds that can exceed 80 Mbps if the third-party device and environment allow.

Introduction:

1. As a cross-device file transfer solution, Huawei Share uses Bluetooth to discover nearby devices and authenticate connections, then sets up peer-to-peer Wi-Fi channels, so as to allow file transfers between phones, PCs, and other devices.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200610060253.13276759665206853245701873972582:50510618025057:2800:649125BB2A38530EF3D7983B9F30CFF0CC09EA283ED614784CFDECE975E31D4D.gif"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200610060253.13276759665206853245701873972582:50510618025057:2800:649125BB2A38530EF3D7983B9F30CFF0CC09EA283ED614784CFDECE975E31D4D.gif[/IMG]​

2. To ensure user experience, Huawei Share uses reliable core technologies in each phase of file transfer.

Devices are detected using in-house bidirectional device discovery technology, without sacrificing the battery or security

Connection authentication using in-house developed password-authenticated key exchange (PAKE) technology

File transfer using high-speed point-to-point transmission technologies, including Huawei-developed channel capability negotiation and actual channel adjustment

Let’s see the working principles:

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200610060359.86733565144052717277116901626963:50510618025057:2800:7926342475C7CD6F26686BB14623DA39A194EB04B90F63E7793A9B9B6B9B99AB.jpg"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200610060359.86733565144052717277116901626963:50510618025057:2800:7926342475C7CD6F26686BB14623DA39A194EB04B90F63E7793A9B9B6B9B99AB.jpg[/IMG]​

Integration part:

Huawei Share kit provides two types of implementation in which first implement depend on Huawei (Sender) to Huawei (Receiver) devices.

The second type of implementation which is based on the Android device (Sender) to Huawei device (Receiver).

In this article, we will implement the second type of implementation which is not available on any documentation or code lab.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200610060426.86476431151266220583898116296582:50510618025057:2800:30F34BDB428BDD755291D8F53AF3A6F0CE0AD1F23890DC2D31F3652224E8D429.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200610060426.86476431151266220583898116296582:50510618025057:2800:30F34BDB428BDD755291D8F53AF3A6F0CE0AD1F23890DC2D31F3652224E8D429.png[/IMG]​

But the first type of implementation is already provided in Huawei code lab with sample code.

What You Will Need?

Hardware Requirements

A computer (desktop or laptop) that runs Windows 7 or Windows 10

A Huawei phone (with the USB cable), which is used for debugging

A third-party Android device, which is used for debugging

Software Requirements

JDK 1.8 or later

Android API (level 26 or higher)

EMUI 10.0 or later

Let’s create a Sample Demo:

1. Create an Android Studio project:

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200610060500.56672168401160679144408537229135:50510618025057:2800:8DA63BC131C35162C3B5863544D5F183DD419C5A5B34B164C43B1251F29B69B3.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200610060500.56672168401160679144408537229135:50510618025057:2800:8DA63BC131C35162C3B5863544D5F183DD419C5A5B34B164C43B1251F29B69B3.png[/IMG]​

2. Enter the file name and project location and click Finish:

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200610060515.18241464003226074088539573015624:50510618025057:2800:1EA39299DB4CCD154C7E1D57E4BFAA5D1B851FC80F621DBF2B2C2A82B5098EDD.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200610060515.18241464003226074088539573015624:50510618025057:2800:1EA39299DB4CCD154C7E1D57E4BFAA5D1B851FC80F621DBF2B2C2A82B5098EDD.png[/IMG]​

3. Add Share SDK in the project:

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200610060537.58083646521586297108663601784319:50510618025057:2800:FC40850CE5DCE5BE3835BE89FB154F4D8EE84E15A657321CC232B8FAC262C73D.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200610060537.58083646521586297108663601784319:50510618025057:2800:FC40850CE5DCE5BE3835BE89FB154F4D8EE84E15A657321CC232B8FAC262C73D.png[/IMG]​

4. We need to add the code repository to the project root directory gradle.

maven {
url 'http://developer.huawei.com/repo/'
}

5. We need to add the following dependencies in our app gradle.

dependencies {
implementation files('libs/sharekit-1.0.1.300.aar')
implementation 'com.android.support:support-annotations:28.0.0'
implementation 'com.android.support:localbroadcastmanager:28.0.0'
implementation 'com.android.support:support-compat:28.0.0'
implementation 'com.google.guava:guava:24.1-android'
}

Note: You need to raise a ticket to get Share Kit SDK “sharekit-1.0.300.aar” file

Click on the below link and raise your ticket.

https://developer.huawei.com/consumer/en/support/feedback/#/

6. We need to add two permission to our android project.

android.permission.READ_EXTERNAL_STORAGE
android.permission.ACCESS_FINE_LOCATION

7. Click Sync now or Sync Project with Gradle Files to build a project.

We will cover code implementation in the next part of this article.

For your information, I will show you the final output of this sample.

Android device (Sender):

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200610060859.36711468348519386917658415497866:50510618025057:2800:C82012211EC612CDE29D7A7F5CD4016BA72003DE1FD65AFB62D98A2FA285F0A6.gif"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200610060859.36711468348519386917658415497866:50510618025057:2800:C82012211EC612CDE29D7A7F5CD4016BA72003DE1FD65AFB62D98A2FA285F0A6.gif[/IMG]

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200610060950.26238476688476791442444861983727:50510618025057:2800:0BF8B3606E244516DDBE4655D18C0BF131341B6AB5F6BA563DACD2AB0BCCE68A.gif"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200610060950.26238476688476791442444861983727:50510618025057:2800:0BF8B3606E244516DDBE4655D18C0BF131341B6AB5F6BA563DACD2AB0BCCE68A.gif[/IMG]

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200610061107.78337866955906157613763559605502:50510618025057:2800:38C93A9340C7A31AAB0D430520805CDABABA0294388C4FFB9BCAC696D064773B.gif"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200610061107.78337866955906157613763559605502:50510618025057:2800:38C93A9340C7A31AAB0D430520805CDABABA0294388C4FFB9BCAC696D064773B.gif[/IMG]​

Huawei device (Receiver):

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200610061238.79225434580714349935517331734317:50510618025057:2800:674BCC4260D245F4DFDA27CDEC9FACB3426D084310386B20E81188ED8E5ECD5D.gif"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200610061238.79225434580714349935517331734317:50510618025057:2800:674BCC4260D245F4DFDA27CDEC9FACB3426D084310386B20E81188ED8E5ECD5D.gif[/IMG]

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200610061238.69594597845046422332490239442843:50510618025057:2800:F7EA2A6234E62A05DB9BAA3913E33E4F140B4FEF1EC5860724E7CAF66FE19E7E.gif"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200610061238.69594597845046422332490239442843:50510618025057:2800:F7EA2A6234E62A05DB9BAA3913E33E4F140B4FEF1EC5860724E7CAF66FE19E7E.gif[/IMG]

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200610061238.06531090303532743198258151392412:50510618025057:2800:1CC8BBAD71B39EAD2A0335CB3DDE5BAA8EBFED85312BB3B4BC0D368987D89512.gif"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200610061238.06531090303532743198258151392412:50510618025057:2800:1CC8BBAD71B39EAD2A0335CB3DDE5BAA8EBFED85312BB3B4BC0D368987D89512.gif[/IMG]

If you have any doubts or queries. Please leave your valuable comment in the comment and ask your question in HUAWEI Developer Forum.​