2024-01-05 11:11:15 +08:00
|
|
|
import UIAbility from '@ohos.app.ability.UIAbility';
|
|
|
|
|
import hilog from '@ohos.hilog';
|
|
|
|
|
import window from '@ohos.window';
|
|
|
|
|
import relationalStore from '@ohos.data.relationalStore'
|
|
|
|
|
import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl';
|
|
|
|
|
// import featureAbility from '@ohos.ability.featureAbility'
|
|
|
|
|
import { makedir } from '../common/service/fileService'
|
|
|
|
|
import {Array2Byte} from '../common/utils/tools'
|
|
|
|
|
|
|
|
|
|
export default class EntryAbility extends UIAbility {
|
|
|
|
|
onCreate(want, launchParam) {
|
|
|
|
|
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onDestroy() {
|
|
|
|
|
const arrClose = [0x55, 0xaa, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00]
|
|
|
|
|
const arrCloseBuffer= Array2Byte(arrClose).buffer
|
|
|
|
|
globalThis?.lightLineUdp?.send(arrCloseBuffer);
|
|
|
|
|
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async onWindowStageCreate(windowStage: window.WindowStage) {
|
|
|
|
|
// this.context
|
|
|
|
|
// Main window is created, set main page for this ability
|
|
|
|
|
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
|
|
|
|
|
|
|
|
|
|
globalThis.carInfo = {}
|
|
|
|
|
globalThis.examinerInfo = {}
|
|
|
|
|
globalThis.deviceNo = '';
|
|
|
|
|
globalThis.hasAuth = false
|
2024-01-31 14:42:14 +08:00
|
|
|
globalThis.version = '2024.11.22.14'
|
2024-02-22 10:40:35 +08:00
|
|
|
globalThis.judgeVersion = '2024.11.22.14'
|
2024-01-31 14:42:14 +08:00
|
|
|
// globalThis.version = '2022.03.14.01'
|
2024-01-05 11:11:15 +08:00
|
|
|
|
|
|
|
|
globalThis.context = this.context;
|
|
|
|
|
globalThis.pathDir = this.context.filesDir;
|
|
|
|
|
console.info('jiangsong globalThis.pathDir = ' + globalThis.pathDir);
|
|
|
|
|
// this.requestPermission(this.context)
|
|
|
|
|
// this.featureAbilityAuth()
|
|
|
|
|
|
|
|
|
|
const windowClass = await windowStage.getMainWindow();
|
|
|
|
|
globalThis.windowClass = windowClass
|
|
|
|
|
await windowClass.setWindowLayoutFullScreen(true)
|
|
|
|
|
// await windowClass.setWindowSystemBarEnable([])
|
|
|
|
|
await windowClass.setWindowSystemBarEnable(['navigation'])
|
|
|
|
|
|
|
|
|
|
windowStage.loadContent('pages/Index', (err, data) => {
|
|
|
|
|
if (err.code) {
|
|
|
|
|
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.userAuth();
|
|
|
|
|
this.creatFiles();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onWindowStageDestroy() {
|
|
|
|
|
// Main window is destroyed, release UI related resources
|
|
|
|
|
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onForeground() {
|
|
|
|
|
// Ability has brought to foreground
|
|
|
|
|
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onBackground() {
|
|
|
|
|
// Ability has back to background
|
|
|
|
|
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
creatFiles() {
|
|
|
|
|
makedir('/testFile');
|
|
|
|
|
}
|
|
|
|
|
userAuth() {
|
|
|
|
|
const permissions: Array<Permissions> = ['ohos.permission.CAMERA','ohos.permission.READ_MEDIA','ohos.permission.WRITE_MEDIA','ohos.permission.FILE_ACCESS_MANAGER'];
|
|
|
|
|
let context = this.context;
|
|
|
|
|
let atManager = abilityAccessCtrl.createAtManager();
|
|
|
|
|
// requestPermissionsFromUser会判断权限的授权状态来决定是否唤起弹窗
|
|
|
|
|
|
|
|
|
|
atManager.requestPermissionsFromUser(context, permissions).then((data) => {
|
|
|
|
|
let grantStatus: Array<number> = data.authResults;
|
|
|
|
|
let length: number = grantStatus.length;
|
|
|
|
|
for (let i = 0; i < length; i++) {
|
|
|
|
|
if (grantStatus[i] === 0) {
|
|
|
|
|
// 用户授权,可以继续访问目标操作
|
|
|
|
|
} else {
|
|
|
|
|
// 用户拒绝授权,提示用户必须授权才能访问当前页面的功能,并引导用户到系统设置中打开相应的权限
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 授权成功
|
|
|
|
|
}).catch((err) => {
|
|
|
|
|
console.error(`Failed to request permissions from user. Code is ${err.code}, message is ${err.message}`);
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|