Overview

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. File transfer speeds can exceed 80 Mbps if the third-party device and environment allow.
The Huawei Share capabilities are sealed deep in the package, then presented in the form of a simplified Engine for developers to integrate with apps and smart devices. By integrating these capabilities, PCs, printers, cameras, and other devices can easily share files with each other. Three SDK development packages are offered to allow quick integration for Android, Linux, and Windows based apps and devices. In this codelab, your will learn how to integrate Huawei Share into Huawei phone apps. Powered by Huawei Share, Huawei devices can send files or text content to non-Huawei devices.

What You Will Create

In this codelab, you will create a demo project and use an implicit intent to call Huawei Share activities in the demo project to complete the overall process setup of the Huawei Share service. Then Huawei phones will be able to share text content or files between each other.

Schematic drawing

What You Will Learn

Hardware Requirements

Software Requirements

What You Need to Be Familiar with

1.Set the configuration file.

Configure the build.gradle file as follows:
Because Huawei phones have integrated Huawei Share, the sample code does not include integration of the Share Engine SDK.
Change the value of minSdkVersion in the build.gradle file to 26, as shown in the following figure.

Click the sync button, as shown in the following figure.

The dialog box shown in the following figure is displayed when the syncing is successful.

2.Share text content.

private void doStartTextIntent() { String text = shareText.getText().toString(); if (TextUtils.isEmpty(text)) { return; } Intent intent = new Intent(Intent.ACTION_SEND); intent.setType(SHARE_INTENT_TYPE); intent.putExtra(Intent.EXTRA_TEXT, "test text"); intent.setPackage(SHARE_PKG); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PackageManager manager = getApplicationContext().getPackageManager(); List<ResolveInfo> infos = manager.queryIntentActivities(intent, 0); if (infos.size() > 0) { // size == 0 indicates that the current device does not support Intent-based sharing. getApplicationContext().startActivity(intent); } }

3.Share files.

private void doStartFileIntent() { String text = shareText.getText().toString(); if (TextUtils.isEmpty(text)) { return; } ArrayList<Uri> uris = getFileUris(text); if (uris.isEmpty()) { return; } Intent intent; if (uris.size() == 1) { // Shares one file. intent = new Intent(Intent.ACTION_SEND); intent.setType(SHARE_INTENT_TYPE); intent.putExtra(Intent.EXTRA_STREAM, uris.get(0)); intent.setPackage(SHARE_PKG); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } else { // Shares multiple files. intent = new Intent(Intent.ACTION_SEND_MULTIPLE); intent.setType(SHARE_INTENT_TYPE); intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); intent.setPackage(SHARE_PKG); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } PackageManager manager = getApplicationContext().getPackageManager(); List<ResolveInfo> infos = manager.queryIntentActivities(intent, 0); if (infos.size() > 0) { // size == 0 indicates that the current device does not support Intent-based sharing. getApplicationContext().startActivity(intent); } }

4.Applying for Permissions

Apply for the following permissions:

android.permission.READ_EXTERNAL_STORAGE

Well done. You have successfully completed this codelab and learned:

1.Enable Huawei Share on your Huawei device.

Huawei Share settings

2.Start the ShareKitDemo program on the Huawei device. The following figure shows the program UI.

ShareKitDemo program UI

After you edit the file to be shared, touch the share button to start sharing the file. To share text, edit the text before sharing.

Selecting the recipient device

3.After you select the recipient device, that device will prompt the user to accept the shared file.

Receiving a file from a third-party device

List of received files in Huawei Share

For more information, please click the following link:
Huawei Share Service Introduction

For details about the APIs, see the API Description for Integrating Share Engine into Huawei Phone Apps.

For details about the sample code, see the Sample Code for Integrating Share Engine into Huawei Phone Apps.

Download

Code copied