Skip to content

Commit

Permalink
[OpenHarmony] update openSetting, add full error info, update save …
Browse files Browse the repository at this point in the history
…API (#1122)
  • Loading branch information
zmtzawqlp authored Apr 30, 2024
1 parent 2523da5 commit 108930a
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 53 deletions.
8 changes: 4 additions & 4 deletions example_ohos/ohos/entry/oh-package.json5
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
author: '',
license: '',
dependencies: {
'@ohos/path_provider_ohos': 'file:./har/path_provider_ohos.har',
'@ohos/url_launcher_ohos': 'file:./har/url_launcher_ohos.har',
'@ohos/video_player_ohos': 'file:./har/video_player_ohos.har',
'@ohos/photo_manager': 'file:./har/photo_manager.har',
path_provider_ohos: 'file:./har/path_provider_ohos.har',
url_launcher_ohos: 'file:./har/url_launcher_ohos.har',
video_player_ohos: 'file:./har/video_player_ohos.har',
photo_manager: 'file:./har/photo_manager.har',
},
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import FlutterEngine from '@ohos/flutter_ohos/src/main/ets/embedding/engine/FlutterEngine';
import Log from '@ohos/flutter_ohos/src/main/ets/util/Log';
import PathProviderPlugin from '@ohos/path_provider_ohos'
import PhotoManagerPlugin from '@ohos/photo_manager'
import UrlLauncherPlugin from '@ohos/url_launcher_ohos'
import VideoPlayerPlugin from '@ohos/video_player_ohos'
import { FlutterEngine, Log } from '@ohos/flutter_ohos';
import PathProviderPlugin from 'path_provider_ohos';
import PhotoManagerPlugin from 'photo_manager';
import UrlLauncherPlugin from 'url_launcher_ohos';
import VideoPlayerPlugin from 'video_player_ohos';

/**
* Generated file. Do not edit.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class AlbumHandler extends HandlerBase implements MethodCallHandlerBase {
result.success(album.count);
}
else {
result.error('', '', '');
result.error(`${call.method} failed`, `not find album by ${id}`, null);
}
}
break;
Expand All @@ -79,7 +79,7 @@ export class AlbumHandler extends HandlerBase implements MethodCallHandlerBase {
));
}
else {
result.error('', '', '');
result.error(`${call.method} failed`, `not find album by ${id}`, null);
}
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ export class PermissionHandler extends HandlerBase implements MethodCallHandlerB
case 'openSetting': {
let applicationInfo = this.context!.applicationInfo;
let wantInfo: Want = {
action: 'action.settings.app.info',
bundleName: 'com.huawei.hmos.settings',
abilityName: 'com.huawei.hmos.settings.MainAbility',
uri: 'application_info_entry',
parameters: {
settingsParamBundleName: applicationInfo.name
pushParams: applicationInfo.name
}
}
await this.uiContext!.startAbility(wantInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class PhotoAssetHandler extends HandlerBase implements MethodCallHandlerB
));
}
else {
result.error('', '', '');
result.error(`${call.method} failed`, `not find assets by ${args}`, null);
}
}
break;
Expand All @@ -51,7 +51,7 @@ export class PhotoAssetHandler extends HandlerBase implements MethodCallHandlerB
result.success(photoAsset.uri);
}
else {
result.error('', '', '');
result.error(`${call.method} failed`, `not find asset by ${id}`, null);
}
}
break;
Expand All @@ -72,7 +72,7 @@ export class PhotoAssetHandler extends HandlerBase implements MethodCallHandlerB
result.success(new Uint8Array(arrayBuffer));
}
else {
result.error('', '', '');
result.error(`${call.method} failed`, `not find asset by ${args}`, null);
}
}
break;
Expand Down Expand Up @@ -124,7 +124,7 @@ export class PhotoAssetHandler extends HandlerBase implements MethodCallHandlerB
result.success(uint8Array);
}
else {
result.error('', '', '');
result.error(`${call.method} failed`, `not find asset by ${args}`, null);
}
}
break;
Expand All @@ -145,7 +145,7 @@ export class PhotoAssetHandler extends HandlerBase implements MethodCallHandlerB
));
}
else {
result.error('', '', '');
result.error(`${call.method} failed`, `not find assets by ${args}`, null);
}
}
break;
Expand All @@ -171,7 +171,7 @@ export class PhotoAssetHandler extends HandlerBase implements MethodCallHandlerB
data.push(...assets);
}
else {
result.error('', '', '');
result.error(`${call.method} failed`, `not find assets by ${args}`, null);
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,40 +73,29 @@ export class SaveHandler extends HandlerBase implements MethodCallHandlerBase {
if (!(await PermissionHandler.permissionWriteCheck())) {
result.error('no ohos.permission.WRITE_IMAGEVIDEO', '', '');
}
let title: string = args.get('title');
let extension: string = photoType == photoAccessHelper.PhotoType.IMAGE ? 'jpg' : 'mp4';
if (title != undefined && title.includes('.')) {
let list: Array<string> = title.split('.')
if (list.length == 2) {
title = list[0];
extension = list[1];
}
}
let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(this.uiContext);
let createOptions: photoAccessHelper.CreateOptions = {};
if (title != undefined) {
createOptions = {
title: title,
};
}
try {
let path = await phAccessHelper.createAsset(photoType, extension, createOptions);
let file = fs.openSync(path, fs.OpenMode.WRITE_ONLY | fs.OpenMode.CREATE);
// if (buffer != undefined) {
let writeLen = await fs.write(file.fd, buffer);
// }
// else if (srcUri != undefined) {
// await fs.copyFile(srcUri, path,);
// }

await fs.close(file.fd);
// can't find it if we do it right now
await new Promise<void>((resolve) => {
setTimeout(() => {
resolve();
}, 1000);
});

try {
let title: string = args.get('title');
let extension: string = photoType == photoAccessHelper.PhotoType.IMAGE ? 'jpg' : 'mp4';
if (title != undefined && title.includes('.')) {
let list: Array<string> = title.split('.')
if (list.length == 2) {
title = list[0];
extension = list[1];
}
}
let createOptions: photoAccessHelper.CreateOptions = {};
if (title != undefined) {
createOptions = {
title: title,
};
}
let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(this.uiContext);
let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = photoAccessHelper.MediaAssetChangeRequest.createAssetRequest(this.uiContext, photoType, extension, createOptions);
assetChangeRequest.addResource(photoType == photoAccessHelper.PhotoType.IMAGE ? photoAccessHelper.ResourceType.IMAGE_RESOURCE : photoAccessHelper.ResourceType.VIDEO_RESOURCE, buffer);
await phAccessHelper.applyChanges(assetChangeRequest);
let asset = assetChangeRequest.getAsset();
let path = asset.uri;
let photoAsset: photoAccessHelper.PhotoAsset | null = await PhotoAssetHandler.getPhotoAsset(path);
if (photoAsset != null) {
result.success(PhotoAssetHandler.photoAssetToMap(photoAsset));
Expand Down

0 comments on commit 108930a

Please sign in to comment.