1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15import router from '@ohos.router'; 16 17const array: Array<string> = [ 18 'ohos.permission.CAMERA', 19 'ohos.permission.MICROPHONE', 20 'ohos.permission.READ_MEDIA', 21 'ohos.permission.WRITE_MEDIA', 22 'ohos.permission.MEDIA_LOCATION' 23]; 24 25interface EventHub { 26 emit(event: string, ...args: Object[]): void 27} 28 29interface AbilityContext { 30 terminateSelf(): Promise<void> 31 32 eventHub: EventHub 33} 34 35@Entry 36@Component 37struct Index { 38 private contexts: AbilityContext 39 contextCaller: any 40 41 async aboutToAppear() { 42 this.contexts = getContext(this) as AbilityContext 43 let data = { 44 context: null, 45 launchWant: null 46 } 47 this.contexts.eventHub.emit("getAbilityData", data) 48 this.contextCaller = data.context 49 await this.contextCaller.requestPermissionsFromUser(array) 50 } 51 52 build() { 53 Column() { 54 Button("扫一扫").fontSize(25).onClick(() => { 55 router.push({ 56 url: "pages/second" 57 }) 58 }).key("btnScan") 59 }.width("100%").height("100%").alignItems(HorizontalAlign.Center).justifyContent(FlexAlign.Center) 60 } 61}