mirror of
https://gitee.com/openharmony/applications_app_samples
synced 2024-11-27 10:40:41 +00:00
!4649 【Sample】GamePuzzle下架medialibrary接口
Merge pull request !4649 from YangXin/GamePuzzle
This commit is contained in:
commit
f7b20c5b0f
@ -29,6 +29,7 @@ VideoComponent/src/main/ets/components
|
||||
| |---Index.ets // 首页
|
||||
```
|
||||
### 具体实现
|
||||
|
||||
+ 游戏中图片裁剪分割的效果实现在ImageModel中,源码参考[ImageModel](entry/src/main/ets/model/ImageModel.ts):
|
||||
+ 获取本地图片:首先使用getMediaLibrary获取媒体库实例,然后使用getFileAssets方法获取文件资源,最后使用getAllObject获取检索结果中的所有文件资产方便展示;
|
||||
+ 裁剪图片准备:裁剪图片需要使用[@ohos.multimedia.image](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-image-kit/js-apis-image.md)接口,裁剪前需要申请图片编辑权限,使用[requestPermissionsFromUser](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-abilityAccessCtrl.md#requestpermissionsfromuser9)申请,源码参考[Index.ets](entry/src/main/ets/pages/Index.ets);
|
||||
@ -36,13 +37,10 @@ VideoComponent/src/main/ets/components
|
||||
|
||||
### 相关权限
|
||||
|
||||
[ohos.permission.READ_MEDIA](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionread_media)
|
||||
|
||||
[ohos.permission.WRITE_MEDIA](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionwrite_media)
|
||||
|
||||
[ohos.permission.MEDIA_LOCATION](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionmedia_location)
|
||||
|
||||
[ohos.permission.READ_IMAGEVIDEO](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionread_imagevideo)
|
||||
|
||||
### 依赖
|
||||
|
||||
不涉及。
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022-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
|
||||
@ -24,8 +24,7 @@ import emitter from '@ohos.events.emitter';
|
||||
import mediaquery from '@ohos.mediaquery';
|
||||
import photoAccessHelper from '@ohos.file.photoAccessHelper';
|
||||
|
||||
const PERMISSIONS: Permissions[] = ['ohos.permission.READ_MEDIA', 'ohos.permission.WRITE_MEDIA',
|
||||
'ohos.permission.MEDIA_LOCATION', 'ohos.permission.MANAGE_MISSIONS', 'ohos.permission.READ_IMAGEVIDEO'];
|
||||
const PERMISSIONS: Permissions[] = ['ohos.permission.MEDIA_LOCATION', 'ohos.permission.MANAGE_MISSIONS', 'ohos.permission.READ_IMAGEVIDEO'];
|
||||
const IMAGE_SIZE: number = px2vp(640)
|
||||
const GAME_TIME: number = 300 // 游戏时长
|
||||
const TAG: string = 'Index'
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022-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
|
||||
@ -57,20 +57,6 @@
|
||||
}
|
||||
],
|
||||
"requestPermissions": [
|
||||
{
|
||||
"name": "ohos.permission.READ_MEDIA",
|
||||
"reason": "$string:app_name",
|
||||
"usedScene": {
|
||||
"when": "always"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.WRITE_MEDIA",
|
||||
"reason": "$string:app_name",
|
||||
"usedScene": {
|
||||
"when": "always"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.MEDIA_LOCATION",
|
||||
"reason": "$string:app_name",
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2023-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
|
||||
@ -14,25 +14,25 @@
|
||||
*/
|
||||
|
||||
import hilog from '@ohos.hilog';
|
||||
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
|
||||
import { describe, it, expect } from '@ohos/hypium';
|
||||
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
|
||||
import { Driver, ON } from '@ohos.UiTest';
|
||||
import dataSharePredicates from '@ohos.data.dataSharePredicates';
|
||||
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
|
||||
import missionManager from '@ohos.app.ability.missionManager';
|
||||
import emitter from '@ohos.events.emitter';
|
||||
import userFileManager from '@ohos.filemanagement.userFileManager';
|
||||
import dataSharePredicates from '@ohos.data.dataSharePredicates';
|
||||
|
||||
const DRIVER = Driver.create();
|
||||
const BUNDLE = 'gamePuzzle';
|
||||
let abilityDelegatorRegistry = AbilityDelegatorRegistry.getAbilityDelegator();
|
||||
|
||||
export default function abilityTest() {
|
||||
describe('ActsAbilityTest', function () {
|
||||
describe('ActsAbilityTest', () => {
|
||||
|
||||
/**
|
||||
* 拉起应用
|
||||
*/
|
||||
it(`${BUNDLE}_StartAbility_001`, 0, async function (done) {
|
||||
it(`${BUNDLE}_StartAbility_001`, 0, async (done: Function) => {
|
||||
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
|
||||
hilog.info(0xF811, 'testTag', 'StartAbility_001 begin');
|
||||
try {
|
||||
@ -51,7 +51,7 @@ export default function abilityTest() {
|
||||
/**
|
||||
* 授权
|
||||
*/
|
||||
it(`${BUNDLE}_GetPermission_001`, 0, async (done) => {
|
||||
it(`${BUNDLE}_GetPermission_001`, 0, async (done: Function) => {
|
||||
hilog.info(0xF811, 'testTag', 'GetPermission_001 begin');
|
||||
await DRIVER.delayMs(2000);
|
||||
let ability = abilityDelegatorRegistry.getAppContext();
|
||||
@ -60,10 +60,6 @@ export default function abilityTest() {
|
||||
let allowBtn = await DRIVER.findComponent(ON.text(await manager.getStringValue($r('app.string.allow'))));
|
||||
await allowBtn.click();
|
||||
await DRIVER.delayMs(1000);
|
||||
await DRIVER.assertComponentExist(ON.text(await manager.getStringValue($r('app.string.allow'))));
|
||||
let allowBtnSecond = await DRIVER.findComponent(ON.text(await manager.getStringValue($r('app.string.allow'))));
|
||||
await allowBtnSecond.click();
|
||||
await DRIVER.delayMs(1000);
|
||||
done();
|
||||
hilog.info(0xF811, 'testTag', 'GetPermission_001 end');
|
||||
})
|
||||
@ -71,16 +67,18 @@ export default function abilityTest() {
|
||||
/**
|
||||
* 决定是否调用相机拍照
|
||||
*/
|
||||
it(`${BUNDLE}_IsTakePhoto_001`, 0, async (done) => {
|
||||
it(`${BUNDLE}_IsTakePhoto_001`, 0, async (done: Function) => {
|
||||
hilog.info(0xF811, 'testTag', 'IsTakePhoto_001 begin');
|
||||
let context = abilityDelegatorRegistry.getAppContext();
|
||||
let manager = mediaLibrary.getMediaLibrary(context);
|
||||
let albums = await manager.getFileAssets({
|
||||
selections: mediaLibrary.FileKey.MEDIA_TYPE + '= ?',
|
||||
selectionArgs: [mediaLibrary.MediaType.IMAGE.toString()]
|
||||
});
|
||||
let mgr = userFileManager.getUserFileMgr(context);
|
||||
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
|
||||
let fetchOptions: userFileManager.FetchOptions = {
|
||||
fetchColumns: [],
|
||||
predicates: predicates.equalTo(userFileManager.ImageVideoKey.FILE_TYPE.toString(), userFileManager.FileType.IMAGE.toString())
|
||||
};
|
||||
let fetchResult: userFileManager.FetchResult<userFileManager.FileAsset> = await mgr.getPhotoAssets(fetchOptions);
|
||||
// 小于两张,就拍照
|
||||
if (albums.getCount() < 2) {
|
||||
if (fetchResult.getCount() < 2) {
|
||||
await abilityDelegatorRegistry.startAbility({
|
||||
bundleName: 'com.ohos.camera',
|
||||
abilityName: 'com.ohos.camera.MainAbility'
|
||||
@ -102,7 +100,7 @@ export default function abilityTest() {
|
||||
/**
|
||||
* 重新吊起应用
|
||||
*/
|
||||
it(`${BUNDLE}_StartAbility_002`, 0, async (done) => {
|
||||
it(`${BUNDLE}_StartAbility_002`, 0, async (done: Function) => {
|
||||
hilog.info(0xF811, 'testTag', 'StartAbility_002 begin');
|
||||
try {
|
||||
await abilityDelegatorRegistry.startAbility({
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2022-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
|
||||
@ -19,9 +19,11 @@ import hilog from '@ohos.hilog';
|
||||
import { Hypium } from '@ohos/hypium';
|
||||
import testsuite from '../test/List.test';
|
||||
import window from '@ohos.window';
|
||||
import Want from '@ohos.app.ability.Want';
|
||||
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
|
||||
|
||||
export default class TestAbility extends UIAbility {
|
||||
onCreate(want, launchParam) {
|
||||
onCreate(want :Want, launchParam: AbilityConstant.LaunchParam) {
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate');
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? '');
|
||||
|
Loading…
Reference in New Issue
Block a user