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

Huawei Share capabilities are open to all apps. They can be seamlessly embedded into the sharing logic of apps that integrate HUAWEI Share Kit, creating a consistent UI for sharing across app. Apps can open the Huawei Share page using the Intent method and call the Huawei Share APIs. For details, see the Huawei Share to Become Available in Apps.

Read on to find out how to quickly integrate HUAWEI Share Kit into phone apps.

Step 1: Configuring files

Because the demo runs on a Huawei phone which has integrated Huawei Share, it does not need to integrate the Share Kit SDK.

1. Configure the build.gradle file for your app:

dependencies {

implementation fileTree(dir: 'libs', include: ['*.aar'])

implementation 'com.android.support:support-compat:28.0.0'

}

2. Change the minSdkVersion value in the file to 26.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/005/808/669/2640852000005808669.20200701075154.39302811482100897974968680283197:50510709011504:2800:1D9413DC04E3559956A7DD0C5290C92A762C031213F3DFFD65A62A70F4E18D5B.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/005/808/669/2640852000005808669.20200701075154.39302811482100897974968680283197:50510709011504:2800:1D9413DC04E3559956A7DD0C5290C92A762C031213F3DFFD65A62A70F4E18D5B.png[/IMG]

3. Click the sync button to synchronize the project.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/005/808/669/2640852000005808669.20200701075210.16834897335279685880349432089096:50510709011504:2800:A8409331DB18FA6F290E01677321B5BECCA8CC967A7A2428129EF4242D860C1E.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/005/808/669/2640852000005808669.20200701075210.16834897335279685880349432089096:50510709011504:2800:A8409331DB18FA6F290E01677321B5BECCA8CC967A7A2428129EF4242D860C1E.png[/IMG]

Step 2: Integrating and developing functions

1. 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);

}

}

2. 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);

}

}

HUAWEI Share Kit is now integrated. But before you get started, make sure you have the following:

· Two Huawei phones running EMUI 9.0 or later for debugging, one which can be used as the sender, and the other which can be used as the receiver

· Java JDK (1.8 or later).

· Android API (level 26 or higher).

· Android Studio development environment: V3.0.1 or later is recommended

For more information about integrating HUAWEI Share Kit into Huawei phone apps, see the Preparations for Integrating HUAWEI Share Kit into Huawei Phone Apps.

For more information about HUAWEI Share Kit, visit HUAWEI Developers.

Recommended reading:

Share Kit | Fully-Open HUAWEI Linux Share Kit Unveiled, Allowing for File Transfers Between Huawei and Linux Devices

Fully-Open HUAWEI Windows Share Kit Unveiled, Offering a New Paradigm for Phone-PC File Transfers