提交 8b5c5bc9 编写于 作者: X xinking129

modify code

Signed-off-by: Nxinking129 <xinxin13@huawei.com>
上级 6079f60d
...@@ -22,111 +22,111 @@ let sequence = 0; ...@@ -22,111 +22,111 @@ let sequence = 0;
let TAG = 'GetRunningProcessInformation' let TAG = 'GetRunningProcessInformation'
let commonStateArr: number[] = [-1, -1, -1, -1] let commonStateArr: number[] = [-1, -1, -1, -1]
let commonEventData = { let commonEventData = {
parameters: { parameters: {
commonStateArr: commonStateArr commonStateArr: commonStateArr
} }
} }
globalThis.StartFloatingAbility = () => { globalThis.StartFloatingAbility = () => {
let want = { let want = {
"deviceId": "", "deviceId": "",
"bundleName": "com.example.getrunningprocessinformationtworeply", // "bundleName": "com.example.getrunningprocessinformationtworeply", //
"abilityName": "EntryAbility" "abilityName": "EntryAbility"
}; };
let options = { let options = {
windowMode: AbilityConstant.WindowMode.WINDOW_MODE_FLOATING, windowMode: AbilityConstant.WindowMode.WINDOW_MODE_FLOATING,
}; };
globalThis.abilityContext.startAbility(want, options, (error) => { globalThis.abilityContext.startAbility(want, options, (error) => {
console.log(TAG, "start floating ability error.code = " + error.code) console.log(TAG, "start floating ability error.code = " + error.code)
}) })
} }
globalThis.StartNormalAbility = () => { globalThis.StartNormalAbility = () => {
let want = { let want = {
"deviceId": "", "deviceId": "",
"bundleName": "com.example.getrunningprocessinformationtworeply", // "bundleName": "com.example.getrunningprocessinformationtworeply", //
"abilityName": "EntryAbility" "abilityName": "EntryAbility"
}; };
globalThis.abilityContext.startAbility(want, (error) => { globalThis.abilityContext.startAbility(want, (error) => {
console.log(TAG, "start normal ability error.code = " + error.code) console.log(TAG, "start normal ability error.code = " + error.code)
}) })
} }
globalThis.GetRunningProcessInfoCallback = () => { globalThis.GetRunningProcessInfoCallback = () => {
globalThis.applicationContext.getRunningProcessInformation((err, data) => { globalThis.applicationContext.getRunningProcessInformation((err, data) => {
if (err) { if (err) {
console.log(TAG, `getRunningProcessInformation err: ` + JSON.stringify(err)); console.log(TAG, `getRunningProcessInformation err: ` + JSON.stringify(err));
} }
else { else {
console.log(TAG, 'Oncreate Callback State: ' + JSON.stringify(data[0].state)); console.log(TAG, 'Oncreate Callback State: ' + JSON.stringify(data[0].state));
commonStateArr[sequence++] = data[0].state commonStateArr[sequence++] = data[0].state
} }
}) })
} }
globalThis.GetRunningProcessInfoPromise = () => { globalThis.GetRunningProcessInfoPromise = () => {
globalThis.applicationContext.getRunningProcessInformation().then((data) => { globalThis.applicationContext.getRunningProcessInformation().then((data) => {
console.log(TAG, 'Oncreate Promise State: ' + JSON.stringify(data[0].state)); console.log(TAG, 'Oncreate Promise State: ' + JSON.stringify(data[0].state));
commonStateArr[sequence++] = data[0].state commonStateArr[sequence++] = data[0].state
}).catch((err) => { }).catch((err) => {
console.log(TAG, `getRunningProcessInformation err: ` + JSON.stringify(err)); console.log(TAG, `getRunningProcessInformation err: ` + JSON.stringify(err));
}); });
} }
globalThis.PublishStateArray = () => { globalThis.PublishStateArray = () => {
commonEvent.publish('processState', commonEventData, (err) => { commonEvent.publish('processState', commonEventData, (err) => {
console.info("====>processState publish err: " + JSON.stringify(err)) console.info("====>processState publish err: " + JSON.stringify(err))
}) })
} }
export default class EntryAbility extends Ability { export default class EntryAbility extends Ability {
onCreate(want, launchParam) { onCreate(want, launchParam) {
sequence = 0 sequence = 0
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? ''); hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? ''); hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? '');
globalThis.want = want globalThis.want = want
globalThis.abilityContext = this.context globalThis.abilityContext = this.context
globalThis.applicationContext = this.context.getApplicationContext(); globalThis.applicationContext = this.context.getApplicationContext();
} }
onDestroy() { onDestroy() {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
} }
onWindowStageCreate(windowStage: Window.WindowStage) { onWindowStageCreate(windowStage: Window.WindowStage) {
// Main window is created, set main page for this ability // Main window is created, set main page for this ability
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/Index', (err, data) => { windowStage.loadContent('pages/Index', (err, data) => {
if (err.code) { if (err.code) {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR);
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return; return;
} }
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
}); });
} }
onWindowStageDestroy() { onWindowStageDestroy() {
// Main window is destroyed, release UI related resources // Main window is destroyed, release UI related resources
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
} }
onForeground() { onForeground() {
// Ability has brought to foreground // Ability has brought to foreground
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
} }
onBackground() { onBackground() {
// Ability has back to background // Ability has back to background
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO); hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册