mirror of
https://gitee.com/openharmony/applications_app_samples
synced 2024-11-28 03:00:49 +00:00
!2263 code目录下编译适配
* [0230]code目录下编译适配 Signed-off-by: zwx1126739 <zhanghong121@huawei.com>
This commit is contained in:
parent
d633ac12cc
commit
8803f57364
@ -15,7 +15,7 @@
|
||||
|
||||
import rpc from "@ohos.rpc"
|
||||
import wantAgent from '@ohos.wantAgent'
|
||||
import ServiceExtensionAbility from '@ohos.application.ServiceExtensionAbility'
|
||||
import ServiceExtension from '@ohos.app.ability.ServiceExtensionAbility'
|
||||
import Logger from '../model/Logger'
|
||||
|
||||
const TAG: string = 'ServiceAbility'
|
||||
@ -78,7 +78,7 @@ class FirstServiceAbilityStub extends rpc.RemoteObject {
|
||||
}
|
||||
}
|
||||
|
||||
export default class ServiceExtAbility extends ServiceExtensionAbility {
|
||||
export default class ServiceExtAbility extends ServiceExtension {
|
||||
onCreate(want) {
|
||||
Logger.info(`${TAG} onCreate, want: ${want.abilityName}`)
|
||||
}
|
||||
|
@ -14,14 +14,14 @@
|
||||
*/
|
||||
|
||||
|
||||
import Ability from '@ohos.application.Ability'
|
||||
import UIAbility from '@ohos.app.ability.UIAbility'
|
||||
import Window from '@ohos.window'
|
||||
import backgroundTaskManager from '@ohos.backgroundTaskManager';
|
||||
import Logger from '../model/Logger'
|
||||
|
||||
const TAG = "EntryAbility"
|
||||
|
||||
export default class EntryAbility extends Ability {
|
||||
export default class EntryAbility extends UIAbility {
|
||||
onCreate(want, launchParam) {
|
||||
Logger.info(TAG, 'Ability onCreate')
|
||||
Logger.info(TAG, `want param: ${JSON.stringify(want)}`)
|
||||
|
@ -14,7 +14,7 @@
|
||||
*/
|
||||
|
||||
import prompt from '@ohos.prompt'
|
||||
import context from '@ohos.application.context'
|
||||
import common from '@ohos.app.ability.common'
|
||||
import rpc from "@ohos.rpc"
|
||||
import Logger from '../model/Logger'
|
||||
|
||||
@ -54,8 +54,8 @@ export class ServiceModel {
|
||||
|
||||
connectService() {
|
||||
Logger.info(`${TAG} onCconnectService begin`)
|
||||
let context = getContext(this) as context.AbilityContext
|
||||
connection = context.connectAbility(
|
||||
let context = getContext(this) as common.UIAbilityContext
|
||||
connection = context.connectServiceExtensionAbility(
|
||||
{
|
||||
deviceId: localDeviceId,
|
||||
bundleName: 'ohos.samples.flybird',
|
||||
@ -78,8 +78,8 @@ export class ServiceModel {
|
||||
})
|
||||
return
|
||||
}
|
||||
let context = getContext(this) as context.AbilityContext
|
||||
context.disconnectAbility(connection)
|
||||
let context = getContext(this) as common.UIAbilityContext
|
||||
context.disconnectServiceExtensionAbility(connection)
|
||||
connection = -1 // 连接状态值设置为-1
|
||||
prompt.showToast({
|
||||
message: 'onDisconnectService disconnect done'
|
||||
|
@ -14,7 +14,7 @@
|
||||
*/
|
||||
|
||||
import router from '@ohos.router';
|
||||
import bundleState from '@ohos.bundleState';
|
||||
import usageStatistics from '@ohos.resourceschedule.usageStatistics';
|
||||
import Logger from '../model/Logger'
|
||||
|
||||
const TAG = "Game"
|
||||
@ -241,7 +241,7 @@ struct Game {
|
||||
}
|
||||
|
||||
showHistoryScore() {
|
||||
bundleState.queryBundleStateInfos(Number(this.beginTime), Number(this.endTime), (err, res) => {
|
||||
usageStatistics.queryBundleStatsInfos(Number(this.beginTime), Number(this.endTime), (err, res) => {
|
||||
if (err) {
|
||||
Logger.info(TAG, `queryBundleStateInfos1 callback failed,because: ${err.code}`)
|
||||
}
|
||||
|
@ -13,15 +13,26 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Ability from '@ohos.application.Ability'
|
||||
import UIAbility from '@ohos.app.ability.UIAbility'
|
||||
import Window from '@ohos.window'
|
||||
import contact from '@ohos.contact'
|
||||
import Logger from '../data/Logger'
|
||||
import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
|
||||
|
||||
export default class EntryAbility extends Ability {
|
||||
const TAG = 'EntryAbility'
|
||||
|
||||
export default class EntryAbility extends UIAbility {
|
||||
async onCreate(want, launchParam) {
|
||||
globalThis.abilityContext = this.context
|
||||
await this.context.requestPermissionsFromUser(['ohos.permission.WRITE_CONTACTS', 'ohos.permission.READ_CONTACTS'])
|
||||
let atManager = abilityAccessCtrl.createAtManager()
|
||||
try {
|
||||
atManager.requestPermissionsFromUser(this.context, ['ohos.permission.WRITE_CONTACTS', 'ohos.permission.READ_CONTACTS']).then((data) => {
|
||||
Logger.info(TAG, `data: ${JSON.stringify(data)}`)
|
||||
}).catch((err) => {
|
||||
Logger.info(TAG, `err: ${JSON.stringify(err)}`)
|
||||
})
|
||||
} catch (err) {
|
||||
Logger.info(TAG, `catch err->${JSON.stringify(err)}`);
|
||||
}
|
||||
contact.queryContacts((err, data) => {
|
||||
if (err) {
|
||||
Logger.info(`queryContacts callback: err->${JSON.stringify(err)}`)
|
||||
|
@ -15,17 +15,27 @@
|
||||
|
||||
import Logger from '../data/Logger'
|
||||
import { Home } from '../component/Home'
|
||||
import context from '@ohos.application.context'
|
||||
|
||||
import common from '@ohos.app.ability.common'
|
||||
import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl'
|
||||
const TAG: string = 'Index'
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct Index {
|
||||
async aboutToAppear() {
|
||||
let permission: string[] = ['ohos.permission.WRITE_CONTACTS', 'ohos.permission.READ_CONTACTS']
|
||||
let ctx = getContext(this) as context.AbilityContext
|
||||
let result = await ctx.requestPermissionsFromUser(permission)
|
||||
let permission: Permissions[] = ['ohos.permission.WRITE_CONTACTS', 'ohos.permission.READ_CONTACTS']
|
||||
let ctx = getContext(this) as common.UIAbilityContext
|
||||
let atManager = abilityAccessCtrl.createAtManager()
|
||||
let result
|
||||
try {
|
||||
result = atManager.requestPermissionsFromUser(ctx, permission).then((data) => {
|
||||
Logger.info(TAG, `data: ${JSON.stringify(data)}`)
|
||||
}).catch((err) => {
|
||||
Logger.info(TAG, `err: ${JSON.stringify(err)}`)
|
||||
})
|
||||
} catch (err) {
|
||||
Logger.info(TAG, `catch err->${JSON.stringify(err)}`);
|
||||
}
|
||||
Logger.info(TAG, `grantPermission,requestPermissionsFromUser,result.requestCode = ${JSON.stringify(result)}`)
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
import fileio from '@ohos.file.fs'
|
||||
import router from '@ohos.router'
|
||||
import contact from '@ohos.contact'
|
||||
import context from '@ohos.application.context'
|
||||
import common from '@ohos.app.ability.common'
|
||||
import Logger from '../data/Logger'
|
||||
|
||||
const TAG: string = 'Setting'
|
||||
@ -80,7 +80,7 @@ export struct Setting {
|
||||
}
|
||||
|
||||
async writeContact() {
|
||||
let ctx = getContext(this) as context.AbilityContext
|
||||
let ctx = getContext(this) as common.UIAbilityContext
|
||||
let path = ctx.filesDir
|
||||
let file = fileio.openSync(`${path}/Contact.json`, fileio.OpenMode.READ_WRITE | fileio.OpenMode.CREATE)
|
||||
for (let i = 0; i < this.contacts.length; i++) {
|
||||
|
@ -13,13 +13,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Ability from '@ohos.application.Ability'
|
||||
import UIAbility from '@ohos.app.ability.UIAbility'
|
||||
import Window from '@ohos.window'
|
||||
import Logger from '../model/Logger'
|
||||
|
||||
const TAG = 'EntryAbility'
|
||||
|
||||
export default class EntryAbility extends Ability {
|
||||
export default class EntryAbility extends UIAbility {
|
||||
onCreate(want, launchParam) {
|
||||
Logger.info(TAG, 'Ability onCreate')
|
||||
Logger.info(TAG, `want param: ${JSON.stringify(want)}`)
|
||||
|
@ -28,11 +28,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Ability from '@ohos.application.Ability'
|
||||
import UIAbility from '@ohos.app.ability.UIAbility'
|
||||
import Window from '@ohos.window'
|
||||
import Logger from '../util/Logger'
|
||||
|
||||
export default class EntryAbility extends Ability {
|
||||
export default class EntryAbility extends UIAbility {
|
||||
onCreate() {
|
||||
Logger.info('Ability onCreate')
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import AbilityStage from "@ohos.application.AbilityStage"
|
||||
import AbilityStage from '@ohos.app.ability.AbilityStage'
|
||||
|
||||
const TAG: string = '[Sample_HealthyDiet]'
|
||||
|
||||
|
@ -13,11 +13,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Ability from '@ohos.application.Ability'
|
||||
import UIAbility from '@ohos.app.ability.UIAbility'
|
||||
|
||||
const TAG: string = '[Sample_HealthyDiet]'
|
||||
|
||||
export default class MainAbility extends Ability {
|
||||
export default class MainAbility extends UIAbility {
|
||||
onCreate(want, launchParam) {
|
||||
console.log(TAG, "MainAbility onCreate")
|
||||
}
|
||||
|
@ -13,11 +13,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Ability from '@ohos.application.Ability'
|
||||
import UIAbility from '@ohos.app.ability.UIAbility'
|
||||
import Window from '@ohos.window'
|
||||
import Logger from '../utils/Logger'
|
||||
|
||||
export default class EntryAbility extends Ability {
|
||||
export default class EntryAbility extends UIAbility {
|
||||
onCreate(want, launchParam) {
|
||||
Logger.info('Ability onCreate')
|
||||
}
|
||||
|
@ -13,11 +13,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import FormExtension from '@ohos.application.FormExtension'
|
||||
import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility'
|
||||
import formBindingData from '@ohos.application.formBindingData'
|
||||
import formInfo from '@ohos.application.formInfo'
|
||||
|
||||
export default class EntryFormAbility extends FormExtension {
|
||||
export default class EntryFormAbility extends FormExtensionAbility {
|
||||
onCreate(want) {
|
||||
// Called to return a FormBindingData object.
|
||||
let formData = {}
|
||||
|
@ -13,7 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import AbilityStage from '@ohos.application.AbilityStage'
|
||||
import AbilityStage from '@ohos.app.ability.AbilityStage'
|
||||
import Logger from '../modle/Logger'
|
||||
|
||||
const TAG: string = 'MyAbilityStage'
|
||||
|
@ -13,12 +13,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Ability from '@ohos.application.Ability'
|
||||
import UIAbility from '@ohos.app.ability.UIAbility'
|
||||
import Logger from '../modle/Logger'
|
||||
|
||||
const TAG: string = 'MainAbility'
|
||||
|
||||
export default class MainAbility extends Ability {
|
||||
export default class MainAbility extends UIAbility {
|
||||
onCreate(want, launchParam) {
|
||||
Logger.info(TAG, '[Demo] MainAbility onCreate')
|
||||
}
|
||||
|
@ -14,12 +14,12 @@
|
||||
*/
|
||||
|
||||
import Logger from '../model/Logger'
|
||||
import Ability from '@ohos.application.Ability'
|
||||
import UIAbility from '@ohos.app.ability.UIAbility'
|
||||
import Window from '@ohos.window'
|
||||
|
||||
const TAG: string = '[Index]'
|
||||
|
||||
export default class EntryAbility extends Ability {
|
||||
export default class EntryAbility extends UIAbility {
|
||||
onCreate(want, launchParam) {
|
||||
Logger.info(TAG, `Ability onCreate want param: ` + JSON.stringify(want) ?? '' + 'launchParam:' + JSON.stringify(launchParam) ?? '')
|
||||
}
|
||||
|
@ -106,11 +106,11 @@ struct Index {
|
||||
console.info(`Callback when the second button is clicked`)
|
||||
if (title.id === $r('app.string.turnOff').id) {
|
||||
this.window = 'Is power off'
|
||||
power.shutdownDevice('shutdown_test')
|
||||
power.shutdown('shutdown_test')
|
||||
console.info(`power_shutdown_device_test success`)
|
||||
} else if (title.id === $r('app.string.restart').id) {
|
||||
this.window = 'Is to restart'
|
||||
power.rebootDevice('reboot_test')
|
||||
power.reboot('reboot_test')
|
||||
console.info(`power_reboot_device_test success`)
|
||||
}
|
||||
}
|
||||
|
@ -13,11 +13,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Ability from '@ohos.application.Ability'
|
||||
import UIAbility from '@ohos.app.ability.UIAbility'
|
||||
import Window from '@ohos.window'
|
||||
import Logger from '../model/Logger'
|
||||
|
||||
export default class EntryAbility extends Ability {
|
||||
export default class EntryAbility extends UIAbility {
|
||||
onCreate(want, launchParam) {
|
||||
Logger.info('Ability onCreate')
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ import promptAction from '@ohos.promptAction'
|
||||
import bundleManager from '@ohos.bundle.bundleManager'
|
||||
import Logger from '../model/Logger'
|
||||
import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
|
||||
import context from '@ohos.application.context'
|
||||
import common from '@ohos.app.ability.common'
|
||||
import { requestModel } from '@ohos/requestModel'
|
||||
|
||||
const TAG: string = '[Index]'
|
||||
@ -31,7 +31,7 @@ struct Index {
|
||||
private atManager: abilityAccessCtrl.AtManager = undefined
|
||||
aboutToAppear() {
|
||||
this.request = new requestModel([PERMISSION])
|
||||
this.request.requestPermission('ohos.samples.abilityaccessctrl', getContext(this) as context.AbilityContext)
|
||||
this.request.requestPermission('ohos.samples.abilityaccessctrl', getContext(this) as common.UIAbilityContext)
|
||||
}
|
||||
|
||||
build() {
|
||||
|
@ -13,11 +13,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Ability from '@ohos.application.Ability'
|
||||
import UIAbility from '@ohos.app.ability.UIAbility'
|
||||
import Window from '@ohos.window'
|
||||
import Logger from '../model/Logger'
|
||||
|
||||
export default class EntryAbility extends Ability {
|
||||
export default class EntryAbility extends UIAbility {
|
||||
onCreate(want, launchParam) {
|
||||
Logger.info('Ability onCreate')
|
||||
AppStorage.SetOrCreate('bundleName', want.parameters.bundleName)
|
||||
|
@ -13,12 +13,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
|
||||
import abilityAccessCtrl ,{Permissions}from '@ohos.abilityAccessCtrl'
|
||||
import promptAction from '@ohos.promptAction'
|
||||
import context from '@ohos.application.context'
|
||||
import common from '@ohos.app.ability.common'
|
||||
import bundleManager from '@ohos.bundle.bundleManager'
|
||||
import Logger from '../../model/Logger'
|
||||
|
||||
const TAG = 'VerifyIndex'
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct Index {
|
||||
@ -27,7 +29,7 @@ struct Index {
|
||||
@State tokenID: number = 0
|
||||
private cancel: string = ''
|
||||
private confirm: string = ''
|
||||
private ctx: context.AbilityContext = getContext(this) as context.AbilityContext
|
||||
private ctx: common.UIAbilityContext = getContext(this) as common.UIAbilityContext
|
||||
|
||||
async aboutToAppear() {
|
||||
let resource = await this.ctx.resourceManager
|
||||
@ -36,10 +38,10 @@ struct Index {
|
||||
let bundleFlag = 0
|
||||
let appInfo = await bundleManager.getApplicationInfo(this.bundleName, bundleFlag)
|
||||
this.tokenID = appInfo.accessTokenId
|
||||
this.grantUserPermissions(this.permission)
|
||||
this.grantUserPermissions(this.permission as Permissions)
|
||||
}
|
||||
|
||||
async grantUserPermissions(grantPermissions: string) {
|
||||
async grantUserPermissions(grantPermissions: Permissions) {
|
||||
let atManager = abilityAccessCtrl.createAtManager()
|
||||
let result = await promptAction.showDialog({
|
||||
title: $r('app.string.title'),
|
||||
|
@ -15,20 +15,20 @@
|
||||
|
||||
import bundleManager from '@ohos.bundle.bundleManager'
|
||||
import Logger from '../model/Logger'
|
||||
import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
|
||||
import context from '@ohos.application.context'
|
||||
import abilityAccessCtrl,{Permissions} from '@ohos.abilityAccessCtrl'
|
||||
import common from '@ohos.app.ability.common'
|
||||
|
||||
const TAG: string = '[requestPermission]'
|
||||
const BUNDLE_NAME: string = 'ohos.samples.abilityaccessctrl'
|
||||
|
||||
export class requestModel {
|
||||
private permissions: Array<string> = []
|
||||
private permissions: Array<Permissions> = []
|
||||
|
||||
constructor(permissions: Array<string>) {
|
||||
constructor(permissions: Array<Permissions>) {
|
||||
this.permissions = permissions
|
||||
}
|
||||
|
||||
async requestPermission(bundleName: string, ctx: context.AbilityContext) {
|
||||
async requestPermission(bundleName: string, ctx: common.UIAbilityContext) {
|
||||
Logger.info('requestPermission start')
|
||||
let bundleFlag = 0
|
||||
let appInfo = await bundleManager.getApplicationInfo(bundleName, bundleFlag)
|
||||
|
Loading…
Reference in New Issue
Block a user