Sharing file(s) between Huawei Phones with Share Engine | Kotlin

İsmail Emre Bayırlı
Huawei Developers
Published in
3 min readNov 17, 2020

--

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. It delivers stable file transfer speeds that can exceed 80 Mbps if the third-party device and environment allow. With Share Engine, developers can use Huawei Share abilities in their apps.

Share engines offers three SDK packages for Android, Linux, and Windows based apps and devices. But if we want to share file (s) between Huawei Phones, we don’t need any SDK package. Let’s talk about Share Engine.

Working Principles

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.

To ensure user experience, Huawei Share uses reliable core technologies in each phase of file transfer. You can find more information about Share Engine in here. Let’s do some coding!

As I mentioned earlier, we don’t need any SDK but we do have some requirements for Share Engine.

  • Android Studio development environment V3.0.1 or later is recommended.
  • Phone development: Huawei phones that run EMUI 9.0 or later and support Huawei Share.

After you make sure you meet the requirements we can start coding.

1- First we need read external storage permission for reading file(s) from storage. Let’s add permission in Manifest file.

2- I will use Activity Result API for starting activities or getting user permissions. Therefore you need to add Activity Result API SDK into your app level build.gradle file. Your file should look like below:

3- After adding permission and SDK initialization, let’s create layout.

4- After, let’s create some functions and variables that we will use in later. First we need storage permission. As i mentioned earlier i will use Activity Result API for this. Sample code below:

5- For getting file from storage we’ll create an instance. After getting file we’ll send selected file in here: (Sending File)

6- User can select multiple file for sending. For this purpose we will create another instance and we’ll send selected files from here: (Sending multiple files)

7- In variables that we created before, you may notice there is a method called createIntent(). These method gets an intent instance and returns a unit block with an intent instance.

So what are we doing in this method. As i mentioned earlier, we don’t need any SDK for using Share Engine between Huawei Phones but we need to give package name for intents. And these type, packages, and flags are common to all methods such as sharing text, file(s). We are initializing our intent’s common properties and returns the intent as ready to use.

8- We can also send text between Huawei Phones: (Sending texts)

9- We created our instances, before we start the project we need to control if phone supports Share Engine. We do this in onCreate():

Let’s bring them all the pieces together. Here is our MainActivity:

Here are the outputs;

Sharing text:

Sharing a file:

Sharing files:

Conclusion

In this article we learned how to share file(s) between Huawei Phones with using Share Engine. You can find more information about Share Engine in here:

Thank you.

--

--