diff --git a/AbilityKit/entry/src/main/ets/entryability/EntryAbilityRequest.ets b/AbilityKit/entry/src/main/ets/entryability/EntryAbilityRequest.ets new file mode 100644 index 0000000000000000000000000000000000000000..a5f002d969aed3f2c02ca76520d2f0d374595147 --- /dev/null +++ b/AbilityKit/entry/src/main/ets/entryability/EntryAbilityRequest.ets @@ -0,0 +1,56 @@ +/* +* FAQ:如何在App启动时让各种权限弹窗的申请自动弹出 + */ + +import { abilityAccessCtrl, AbilityConstant, ConfigurationConstant, + PermissionRequestResult, + UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; +import { BusinessError } from '@kit.BasicServicesKit'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + // [Start at_manager] + windowStage.loadContent('pages/Index', (err) => { + let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager(); + atManager.requestPermissionsFromUser(this.context, ['ohos.permission.ACCESS_BLUETOOTH']) + .then((data: PermissionRequestResult) => { + console.info('data:' + JSON.stringify(data)); + console.info('data permissions:' + data.permissions); + console.info('data authResults:' + data.authResults); + }).catch((err: BusinessError) => { + console.error('data:' + JSON.stringify(err)); + }); + }); + // [End at_manager] + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/AbilityKit/entry/src/main/ets/entryability/EntryAbilityStageEvent.ets b/AbilityKit/entry/src/main/ets/entryability/EntryAbilityStageEvent.ets new file mode 100644 index 0000000000000000000000000000000000000000..6281639778b6ec2b8eb2cd3ef72ead1094b47811 --- /dev/null +++ b/AbilityKit/entry/src/main/ets/entryability/EntryAbilityStageEvent.ets @@ -0,0 +1,62 @@ +/* +* FAQ:如何判断应用当前在前台/后台 + */ + +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + // [Start stage_event] + // EntryAbility.ets + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + try { + windowStage.on('windowStageEvent', (data) => { + if (data === window.WindowStageEventType.SHOWN) { + hilog.info(0x0000, 'testTag', '%{public}s', 'window stage is shown'); + } else if (data === window.WindowStageEventType.HIDDEN) { + hilog.info(0x0000, 'testTag', '%{public}s', 'window stage is hidden'); + } + }); + } catch (err) { + hilog.error(0x0000, 'testTag', '%{public}s', 'Failed to enable the listener for ' + + 'window stage event changes. Cause:' + JSON.stringify(err)); + } + 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) ?? ''); + }); + } + // [End stage_event] + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/AbilityKit/entry/src/main/ets/myabilitystage/MyAbilityStage.ets b/AbilityKit/entry/src/main/ets/myabilitystage/MyAbilityStage.ets new file mode 100644 index 0000000000000000000000000000000000000000..32f7ea7e5950f6e3dba53d0815ab04792989930d --- /dev/null +++ b/AbilityKit/entry/src/main/ets/myabilitystage/MyAbilityStage.ets @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:如何使用AbilityStage的生命周期函数 + */ + +// [Start my_ability_stage] +import { AbilityStage, Want } from '@kit.AbilityKit'; + +export default class MyAbilityStage extends AbilityStage { + onCreate(): void { + // When the HAP of the application is first loaded, initialize the operation for the module + } + + onAcceptWant(want: Want): string { + // Triggered only when UIAbility is configured in specified startup mode + return 'MyAbilityStage'; + } +} +// [End my_ability_stage] diff --git a/AbilityKit/entry/src/main/ets/pages/BundleFlags.ets b/AbilityKit/entry/src/main/ets/pages/BundleFlags.ets new file mode 100644 index 0000000000000000000000000000000000000000..7750876a0fe4a2b5a684915888e12099a844e63a --- /dev/null +++ b/AbilityKit/entry/src/main/ets/pages/BundleFlags.ets @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:如何获取指定Bundle Name的Ability信息 + */ + +// [Start bundle_manager] +// Get appInfo with metadataArray information +import { bundleManager } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION | bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_METADATA; +try { + bundleManager.getBundleInfoForSelf(bundleFlags).then((data) => { + hilog.info(0x0000, 'testTag', 'getBundleInfoForSelf successfully. Data: %{public}s', JSON.stringify(data)); + }).catch((err: BusinessError) => { + hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed. Cause: %{public}s', err.message); + }); +} catch (err) { + let message = (err as BusinessError).message; + hilog.error(0x0000, 'testTag', 'getBundleInfoForSelf failed: %{public}s', message); +} +// [End bundle_manager] \ No newline at end of file diff --git a/AbilityKit/entry/src/main/ets/pages/Exceptionhandle.ets b/AbilityKit/entry/src/main/ets/pages/Exceptionhandle.ets new file mode 100644 index 0000000000000000000000000000000000000000..4b5b44571ca1d8b312cbeeb8ec88facd3a83fc68 --- /dev/null +++ b/AbilityKit/entry/src/main/ets/pages/Exceptionhandle.ets @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:onUnhandledException与onException回调分别什么时候触发 + */ + +// [Start exception_handle] +import { errorManager } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +let observer: errorManager.ErrorObserver = { + onUnhandledException(errorMsg) { + console.error('onUnhandledException, errorMsg: ', errorMsg); + }, + onException(errorObj) { + console.log('onException, name: ', errorObj.name); + console.log('onException, message: ', errorObj.message); + if (typeof (errorObj.stack) === 'string') { + console.log('onException, stack: ', errorObj.stack); + } + } +}; + +try { + errorManager.on('error', observer); +} catch (error) { + console.error(`registerErrorObserver failed, error.code: ${(error as BusinessError).code}, error.message: ${(error as BusinessError).message}`); +} +// [End exception_handle] \ No newline at end of file diff --git a/AbilityKit/entry/src/main/ets/pages/GetCacheDirectoryView.ets b/AbilityKit/entry/src/main/ets/pages/GetCacheDirectoryView.ets new file mode 100644 index 0000000000000000000000000000000000000000..47e4a1dd9331afe9556d81e2c18ca747aaefc33d --- /dev/null +++ b/AbilityKit/entry/src/main/ets/pages/GetCacheDirectoryView.ets @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:如何获取当前应用程序缓存目录 + */ + +// [Start get_cache] +import { common } from '@kit.AbilityKit'; + +@Entry +@Component +export struct GetCacheDirectoryView { + private context = getContext(this) as common.UIAbilityContext; + @State cachePath: string = ''; + + build() { + Column() { + Text(this.cachePath) + .margin({ bottom: 24 }) + Button() { + Text('Get the application cache directory address') + } + .onClick(() => { + const applicationContext = this.context.getApplicationContext(); + // Get the application file path + const cacheDir = applicationContext.cacheDir; + this.cachePath = cacheDir + '/test.txt'; + }) + .width(300) + .height(50) + } + .justifyContent(FlexAlign.Center) + .width('100%') + .height('100%') + } +} +// [End get_cache] \ No newline at end of file diff --git a/AbilityKit/entry/src/main/ets/pages/GetRaw.ets b/AbilityKit/entry/src/main/ets/pages/GetRaw.ets new file mode 100644 index 0000000000000000000000000000000000000000..5f811eb1a517b64f4f44d678e284a0907b0df5e4 --- /dev/null +++ b/AbilityKit/entry/src/main/ets/pages/GetRaw.ets @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:如何通过resourceManager获取rawFile路径下的文件 + */ + +// [Start get_raw] +import { BusinessError } from '@kit.BasicServicesKit'; +import { common } from '@kit.AbilityKit'; + +// Passing in '' indicates obtaining a list of files in the root directory of rawfile +try { + let context = getContext(this) as common.UIAbilityContext; + context.resourceManager.getRawFileList('', (error: BusinessError, value: Array) => { + if (error != null) { + console.error(`callback getRawFileList failed, error code: ${error.code}, message: ${error.message}.`); + } else { + let rawFile = value; + } + }); +} catch (error) { + let code = (error as BusinessError).code; + let message = (error as BusinessError).message; + console.error(`callback getRawFileList failed, error code: ${code}, message: ${message}.`); +} +// [End get_raw] \ No newline at end of file diff --git a/AbilityKit/entry/src/main/ets/pages/GetUIAbilityContext.ets b/AbilityKit/entry/src/main/ets/pages/GetUIAbilityContext.ets new file mode 100644 index 0000000000000000000000000000000000000000..26778c0ba6d8f9c350c9d49cc8cdecb8260d957c --- /dev/null +++ b/AbilityKit/entry/src/main/ets/pages/GetUIAbilityContext.ets @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:在使用UIAbilityContext时报401“The context must be a valid Context”的Context类型错误 + */ + +// [Start get_ui_ability] +import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { + let uiAbilityContext = this.context; + // ... + } +} +// [End get_ui_ability] \ No newline at end of file diff --git a/AbilityKit/entry/src/main/ets/pages/LittleEndianPage.ets b/AbilityKit/entry/src/main/ets/pages/LittleEndianPage.ets new file mode 100644 index 0000000000000000000000000000000000000000..c513b412592b163f62c7b7a5d792650d5edb0d0c --- /dev/null +++ b/AbilityKit/entry/src/main/ets/pages/LittleEndianPage.ets @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:HarmonyOS Next系统属于大端还是小端 + */ + +// [Start little_endian] +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + + isLittleEndian(): boolean { + const buffer = new ArrayBuffer(2); + const uint8Array = new Uint8Array(buffer); + const uint16Array = new Uint16Array(buffer); + // Write 0xAA and 0xBB into the buffer + uint8Array[0] = 0xAA; + uint8Array[1] = 0xBB; + // If read in small order, 0xBBAA will be interpreted as 48042 + // If read in big endian order, 0xAABB will be interpreted as 43707 + return uint16Array[0] === 0xBBAA; + } + + + aboutToAppear() { + if (this.isLittleEndian()) { + console.log('Small end'); + } else { + console.log('Big end'); + } + } + + + build() { + RelativeContainer() { + Text(this.message) + .id('HelloWorld') + .fontSize(50) + .fontWeight(FontWeight.Bold) + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + } + .height('100%') + .width('100%') + } +} +// [End little_endian] \ No newline at end of file diff --git a/AbilityKit/entry/src/main/ets/pages/MainAbility.ets b/AbilityKit/entry/src/main/ets/pages/MainAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..5e2a2e4d24e565998d970b5e104564da88a952d0 --- /dev/null +++ b/AbilityKit/entry/src/main/ets/pages/MainAbility.ets @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:UIAbility和UIExtensionAbility有什么区别?分别推荐在什么场景使用 + */ + +// [Start ui_ability] +import { UIAbility } from "@kit.AbilityKit"; +import { window } from "@kit.ArkUI"; + +// MainAbility.ets +export default class MainAbility extends UIAbility { + onWindowStageCreate(windowStage: window.WindowStage) { + windowStage.loadContent("pages/MainPage", (err) => { + if (err) console.error("Page loading failed"); + }); + } +} +// [End ui_ability] \ No newline at end of file diff --git a/AbilityKit/entry/src/main/ets/pages/PublishCB.ets b/AbilityKit/entry/src/main/ets/pages/PublishCB.ets new file mode 100644 index 0000000000000000000000000000000000000000..9ded65f96602b91be5c773dda15790b20c23549c --- /dev/null +++ b/AbilityKit/entry/src/main/ets/pages/PublishCB.ets @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:ExtensionAbility如何与主进程通信 + */ + +// [Start publish_cb] +import { commonEventManager } from '@kit.BasicServicesKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + + +// Publish public event callbacks +function publishCB(err: BusinessError) { + if (err) { + console.error(`Failed to publish common event. Code is ${err.code}, message is ${err.message}`); + } else { + console.info(`Succeeded in publishing common event.`); + } +} +// Publish public events +try { + commonEventManager.publish("event", publishCB); +} catch (error) { + let err: BusinessError = error as BusinessError; + console.error(`Failed to publish common event. Code is ${err.code}, message is ${err.message}`); +} +// [End publish_cb] \ No newline at end of file diff --git a/AbilityKit/entry/src/main/ets/pages/StartAbility.ets b/AbilityKit/entry/src/main/ets/pages/StartAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..8eebd91f6a825243d9b588b2c9a3a74d4973adae --- /dev/null +++ b/AbilityKit/entry/src/main/ets/pages/StartAbility.ets @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:如何实现通过调用其他已安装的应用来打开特定文件 + */ + +// [Start import_module] +import common from '@ohos.app.ability.common'; +import Want from '@ohos.app.ability.Want'; +import wantConstant from '@ohos.app.ability.wantConstant'; +import { BusinessError } from '@ohos.base'; +// [End import_module] + +// [Start request_want] +// Construct request data Want, taking opening a Word file as an example +let wantInfo: Want = { + uri: 'file://.../test.docx', // Indicate the URI path of the file to be opened, usually used in conjunction with type + type: 'application/msword', // Indicate the type of file to be opened + flags: wantConstant.Flags.FLAG_AUTH_WRITE_URI_PERMISSION, // Authorization to perform write operations on URI +} +// [End request_want] + +// [Start start_ability] +// Call the startAbility interface to open files +let context = getContext(this) as common.UIAbilityContext; +context.startAbility(wantInfo).then(() => { + // ... +}).catch((err: BusinessError) => { + // ... +}) +// [End start_ability] \ No newline at end of file diff --git a/AbilityKit/entry/src/main/ets/pages/StartAppGallery.ets b/AbilityKit/entry/src/main/ets/pages/StartAppGallery.ets new file mode 100644 index 0000000000000000000000000000000000000000..9545dac9f02cdebd75ee25a308ac23caf876309f --- /dev/null +++ b/AbilityKit/entry/src/main/ets/pages/StartAppGallery.ets @@ -0,0 +1,59 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:如何拉起应用市场界面 + */ + +// [Start start_app_gallery] +import { common, Want } from '@kit.AbilityKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +// Pull up the application details interface corresponding to the application market +function startAppGalleryDetailAbility(context: common.UIAbilityContext, bundleName: string): void { + let want: Want = { + action: 'ohos.want.action.appdetail', + uri: 'store://appgallery.huawei.com/app/detail?id=' + bundleName, // BundleName is the package name of the application that needs to open the application details + }; + context.startAbility(want).then(() => { + console.info('Start Ability successfully.'); + }).catch((err: BusinessError) => { + console.error(`Failed to startAbility. Code: ${err.code}, message: ${err.message}`); + }); +} + +@Entry +@Component +struct StartAppGalleryDetailAbilityView { + @State message: string = 'Pull up the application market details page'; + + build() { + Row() { + Column() { + Button(this.message) + .fontSize(24) + .fontWeight(FontWeight.Bold) + .onClick(() => { + const context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; + const bundleName = 'com.example.xxx'; + startAppGalleryDetailAbility(context, bundleName); + }) + } + .width('100%') + } + .height('100%') + } +} +// [End start_app_gallery] \ No newline at end of file diff --git a/AbilityKit/entry/src/main/ets/pages/StartCallDialog.ets b/AbilityKit/entry/src/main/ets/pages/StartCallDialog.ets new file mode 100644 index 0000000000000000000000000000000000000000..bec0105aa2b49639a566a54e8a9d2b60148993de --- /dev/null +++ b/AbilityKit/entry/src/main/ets/pages/StartCallDialog.ets @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:如何拉起拨号界面并指定号码 + */ + +// [Start start_call_dialog] +import { call } from '@kit.TelephonyKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + +function startCallDialog(): void { + let isSupport = call.hasVoiceCapability(); + if (!isSupport) { + console.error('Not support voice capability.'); + return; + } + + call.makeCall('16888888888', (err: BusinessError) => { + if (err) { + console.error(`Failed to make call. Code is ${err.code}, Message is ${err.message}`); + return; + } + console.info('Succeeded in making call.'); + }) +} + +@Entry +@Component +struct StartCallDialogView { + @State message: string = 'How to pull up the dialing interface and specify the number'; + + build() { + Row() { + Column() { + Button(this.message) + .fontSize(24) + .fontWeight(FontWeight.Bold) + .onClick(() => { + startCallDialog(); + }) + } + .width('100%') + } + .height('100%') + } +} +// [End start_call_dialog] \ No newline at end of file diff --git a/AbilityKit/entry/src/main/ets/pages/SubscribeCB.ets b/AbilityKit/entry/src/main/ets/pages/SubscribeCB.ets new file mode 100644 index 0000000000000000000000000000000000000000..58b80b562672239c7f0cf8bb48f242d1275de7f5 --- /dev/null +++ b/AbilityKit/entry/src/main/ets/pages/SubscribeCB.ets @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:ExtensionAbility如何与主进程通信 + */ + +// [Start subscribe_cb] +import { BusinessError } from '@kit.BasicServicesKit'; +import { commonEventManager } from '@kit.BasicServicesKit'; + +// Define subscribers to save successfully created subscriber objects, which can be used to complete subscription and unsubscribe actions in the future +let subscriber: commonEventManager.CommonEventSubscriber; +// Subscriber information +let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { + events: ["event"] +}; +// Subscribe to public event callbacks +function SubscribeCB(err: BusinessError, data: commonEventManager.CommonEventData) { + if (err) { + console.error(`Failed to subscribe. Code is ${err.code}, message is ${err.message}`); + } else { + console.info(`Succeeded in subscribing, data is ` + JSON.stringify(data)); + } +} +// Create subscriber callback +function createCB(err: BusinessError, commonEventSubscriber: commonEventManager.CommonEventSubscriber) { + if(!err) { + console.info(`Succeeded in creating subscriber.`); + subscriber = commonEventSubscriber; + // Subscribe to public events + try { + commonEventManager.subscribe(subscriber, SubscribeCB); + } catch (error) { + let err: BusinessError = error as BusinessError; + console.error(`Failed to subscribe. Code is ${err.code}, message is ${err.message}`); + } + } else { + console.error(`Failed to create subscriber. Code is ${err.code}, message is ${err.message}`); + } +} +// Create subscribers +try { + commonEventManager.createSubscriber(subscribeInfo, createCB); +} catch (error) { + let err: BusinessError = error as BusinessError; + console.error(`Failed to create subscriber. Code is ${err.code}, message is ${err.message}`); +} +// [End subscribe_cb] \ No newline at end of file diff --git a/AbilityKit/entry/src/main/ets/pages/UIExtAbility.ets b/AbilityKit/entry/src/main/ets/pages/UIExtAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..2dfcd387865f9c83cd8e314728a6b944f06f3747 --- /dev/null +++ b/AbilityKit/entry/src/main/ets/pages/UIExtAbility.ets @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2024 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* +* FAQ:UIAbility和UIExtensionAbility有什么区别?分别推荐在什么场景使用 + */ + +// [Start ui_ext_ability] +import { UIExtensionAbility, AbilityConstant } from '@kit.AbilityKit'; + +export default class UIExtAbility extends UIExtensionAbility { + onCreate(launchParam: AbilityConstant.LaunchParam) { + console.log(`onCreate, launchParam: ${JSON.stringify(launchParam)}`); + } +} +// [End ui_ext_ability] \ No newline at end of file diff --git a/AbilityKit/entry/src/main/module_fullscreen.json5 b/AbilityKit/entry/src/main/module_fullscreen.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7944299806290696d6588bac64f3d20c3ab5c13d --- /dev/null +++ b/AbilityKit/entry/src/main/module_fullscreen.json5 @@ -0,0 +1,59 @@ +/* +* FAQ:如何禁用窗口的全屏显示功能 + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + // [Start support_window] + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "supportWindowMode": ["split", "floating"], + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + // [End support_window] + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ] + } +} \ No newline at end of file diff --git a/AbilityKit/entry/src/main/module_myability.json5 b/AbilityKit/entry/src/main/module_myability.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b23cc2d23e99b9636e8608e963c86af1fce71960 --- /dev/null +++ b/AbilityKit/entry/src/main/module_myability.json5 @@ -0,0 +1,59 @@ +/* +* FAQ:如何使用AbilityStage的生命周期函数 + */ + +{ + "module": { + "name": "entry", + "type": "entry", + // [Start my_ability_entry] + "srcEntry": "./ets/myabilitystage/MyAbilityStage.ets", + // [End my_ability_entry] + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ] + } +} \ No newline at end of file diff --git a/AbilityKit/entry/src/main/module_remove.json5 b/AbilityKit/entry/src/main/module_remove.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c65392a93df083ef6d5ad7bb9e6647bb08ce9e67 --- /dev/null +++ b/AbilityKit/entry/src/main/module_remove.json5 @@ -0,0 +1,59 @@ +/* +* FAQ:如何在UIAbility调用terminateSelf()后设置不保留最近任务列表中的快照 + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + // [Start remove_mission] + "removeMissionAfterTerminate": true, + // [End remove_mission] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ] + } +} \ No newline at end of file diff --git a/AbilityKit/entry/src/main/module_request.json5 b/AbilityKit/entry/src/main/module_request.json5 new file mode 100644 index 0000000000000000000000000000000000000000..df9a919eeb3c7e6d2c3e369b3f7dbbecb6e6ce13 --- /dev/null +++ b/AbilityKit/entry/src/main/module_request.json5 @@ -0,0 +1,70 @@ +/* +* FAQ:如何在App启动时让各种权限弹窗的申请自动弹出 + */ + +{ + "module": { + "name": "entry", + "type": "entry", + // [Start request_permissions] + "requestPermissions": [ + { + "name": "ohos.permission.ACCESS_BLUETOOTH", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "inuse" + }, + "reason": "$string:app_name" + } + ], + // [End request_permissions] + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ] + } +} \ No newline at end of file diff --git a/AbilityKit/entry/src/main/module_startability.json5 b/AbilityKit/entry/src/main/module_startability.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a932b4f545da868ce3201500186f950d396f8ce8 --- /dev/null +++ b/AbilityKit/entry/src/main/module_startability.json5 @@ -0,0 +1,33 @@ +/* +* FAQ:如何实现通过调用其他已安装的应用来打开特定文件 + */ + +// [Start start_ability_config] +{ + "module": { + // ... + "abilities": [ + { + // ... + "skills": [ + { + "actions": [ + "ohos.want.action.viewData" // Declaration of Data Processing Capability + ], + "uris": [ + { + // Allow opening Word files in URI that start with the file://protocol to identify the local file + "scheme": "file", + "type": "application/msword", // Indicates supported file types for opening + "linkFeature": "FileOpen" // The function of this URI is to open files + } + // ... + ] + // ... + } + ] + } + ] + } +} +// [End start_ability_config] \ No newline at end of file diff --git a/AbilityKit/entry/src/main/module_want.json5 b/AbilityKit/entry/src/main/module_want.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d37e94a4e59cd2b7118661ee0b1e374f94f49ad6 --- /dev/null +++ b/AbilityKit/entry/src/main/module_want.json5 @@ -0,0 +1,33 @@ +/* +* FAQ:如何实现通过调用其他已安装的应用来打开特定文件 + */ + +// [Start module_want] +{ + "module": { + // ... + "abilities": [ + { + // ... + "skills": [ + { + "actions": [ + "ohos.want.action.viewData" // Declaration of Data Processing Capability + ], + "uris": [ + { + // Allow opening Word files in URI that start with the file://protocol to identify the local file + "scheme": "file", + "type": "application/msword", // Indicates supported file types for opening + "linkFeature": "FileOpen" // The function of this URI is to open files + } + // ... + ] + // ... + } + ] + } + ] + } +} +// [End module_want] \ No newline at end of file diff --git a/AbilityKit/entry/src/main/resources/base/profile/main_pages.json b/AbilityKit/entry/src/main/resources/base/profile/main_pages.json index 83e757edffd0df0c9640cd78bdee45f887e55861..77841c501f99f578f87fcf00cab02bf24491c960 100644 --- a/AbilityKit/entry/src/main/resources/base/profile/main_pages.json +++ b/AbilityKit/entry/src/main/resources/base/profile/main_pages.json @@ -2,6 +2,8 @@ "src": [ "pages/Index", "pages/PullUpBrowserApplication", - "pages/PullUpCamera" + "pages/PullUpCamera", + "pages/GetCacheDirectoryView", + "pages/LittleEndianPage" ] } \ No newline at end of file