Starting from version 5.1.0(18), an app can check whether it is started by System Share.
When a target app integrated with System Share is started, the app needs to determine whether it is started by System Share to process the sharing service accordingly.
When the shared content is processed using the UIAbility, you can check whether the value of the LaunchParam.launchReasonMessage parameter is ReasonMessage_SystemShare in onCreate or onNewWant.
When the shared content is processed using the UIExtensionAbility, you can check whether the value of the LaunchParam.launchReasonMessage parameter is ReasonMessage_SystemShare in onCreate.
Process the shared content using the UIAbility.
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { window } from '@kit.ArkUI';
export default class ShareUIAbility extends UIAbility {
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
if (launchParam.launchReasonMessage === 'ReasonMessage_SystemShare') {
// Identify that the app is started by System Share.
console.info('Startup reason: System Share');
}
}
onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void {
if (launchParam.launchReasonMessage === 'ReasonMessage_SystemShare') {
// Identify that the app is started by System Share.
console.info('Startup reason: System Share');
}
}
onWindowStageCreate(windowStage: window.WindowStage): void {
windowStage.loadContent('pages/ShareUIPage'); // This is only an example. Replace it with the actual path.
}
} Process the shared content using the UIExtensionAbility.
import { AbilityConstant, ShareExtensionAbility, UIExtensionContentSession, Want } from '@kit.AbilityKit';
export default class ShareExtAbility extends ShareExtensionAbility {
onCreate(launchParam: AbilityConstant.LaunchParam): void {
if (launchParam.launchReasonMessage === 'ReasonMessage_SystemShare') {
// Identify that the app is started by System Share.
console.info('Startup reason: System Share');
}
}
onSessionCreate(want: Want, session: UIExtensionContentSession) {
session.loadContent('pages/ShareExtDialog'); // This is only an example. Replace it with the actual path.
}
}