This function is available only to enterprise apps. Starting from version 6.0.1(21), a host app developer can configure the target app list (supporting up to 50 target apps). After the configuration, only the target apps in the list can be displayed in the recommendation area and sharing mode area of the system sharing panel.
This capability is restricted currently. To use it, you need to apply for the ohos.permission.SET_SYSTEMSHARE_APPLAUNCHTRUSTLIST permission.
This permission is used by a host app to restrict the supported target apps. This permission is available only to enterprise apps, enabling them to restrict target apps to a set of trusted apps for secure internal data sharing.
When applying for the permission, you need to enter the enterprise app information and its application scenario in reasonPrompt. For example, the permission is used by the XXX enterprise app to restrict sharing of the enterprise's internal information only within the enterprise.
For details about how to apply for a restricted permission, please refer to Requesting Restricted Permissions.
Declare the permission required by your app under requestPermissions in the module.json5 file. For details, please refer to Declaring Permissions.
{
"module": {
// ...
"requestPermissions": [
{
"name": "ohos.permission.SET_SYSTEMSHARE_APPLAUNCHTRUSTLIST",
"reason": '$string:permission_reason_set_system_share_app_launch_trust_list'
},
]
}
} Set the appLaunchTrustInfo parameter to specify the target apps that can be displayed on the sharing panel.
import { common } from '@kit.AbilityKit';
import { systemShare } from '@kit.ShareKit';
import { uniformTypeDescriptor as utd } from '@kit.ArkData';
@Component
export struct ShareAppTrustInfo {
build() {
Button('share').onClick(() => {
this.share();
})
}
private share() {
// Construct ShareData. You need to configure a valid data record.
let data: systemShare.SharedData = new systemShare.SharedData({
utd: utd.UniformDataType.PLAIN_TEXT,
content: 'Hello HarmonyOS'
});
let uiContext: UIContext = this.getUIContext();
// Build ShareController.
let controller: systemShare.ShareController = new systemShare.ShareController(data);
let context: common.UIAbilityContext = uiContext.getHostContext() as common.UIAbilityContext;
// Display the sharing panel.
controller.show(context, {
previewMode: systemShare.SharePreviewMode.DEFAULT,
selectionMode: systemShare.SelectionMode.SINGLE,
appLaunchTrustInfo: ['5765880207853060000', '1171817433862770000'], // This is only an example of appidentifiers of target apps.
})
}
}