Commit 1658cb3d by tanghuan

优化打开相机和相册功能

1 parent 4c8cf445
...@@ -14,9 +14,14 @@ class SysAlbumHandler extends MessageHandler { ...@@ -14,9 +14,14 @@ class SysAlbumHandler extends MessageHandler {
return false; return false;
} }
// 使用 ACTION_MAIN + CATEGORY_APP_GALLERY 打开系统图库应用
// 等同于点击桌面图库图标
// FLAG_ACTIVITY_NEW_TASK (0x10000000) 让图库在独立任务栈中打开,
// Flutter APP 保留在自己的任务栈,用户通过最近任务键可切回
const intent = AndroidIntent( const intent = AndroidIntent(
action: 'android.intent.action.VIEW', action: 'android.intent.action.MAIN',
data: 'content://media/external/images/media', category: 'android.intent.category.APP_GALLERY',
flags: <int>[0x10000000],
); );
await intent.launch(); await intent.launch();
return true; return true;
......
...@@ -5,8 +5,8 @@ import 'package:appframe/services/dispatcher.dart'; ...@@ -5,8 +5,8 @@ import 'package:appframe/services/dispatcher.dart';
/// sysCamera 指令处理类 /// sysCamera 指令处理类
/// ///
/// 打开系统相机进行拍照或录像,仅 Android 平台生效。 /// 打开系统相机应用(等同于点击桌面相机图标),仅 Android 平台生效。
/// 可选参数 type:'photo'(默认,拍照)或 'video'(录像)。 /// 可选参数 type:'photo'(默认,拍照模式)或 'video'(录像模式)。
/// H5 调用示例:{ "cmd": "sysCamera" } 或 { "cmd": "sysCamera", "params": { "type": "video" } } /// H5 调用示例:{ "cmd": "sysCamera" } 或 { "cmd": "sysCamera", "params": { "type": "video" } }
class SysCameraHandler extends MessageHandler { class SysCameraHandler extends MessageHandler {
@override @override
...@@ -20,9 +20,11 @@ class SysCameraHandler extends MessageHandler { ...@@ -20,9 +20,11 @@ class SysCameraHandler extends MessageHandler {
type = params['type'] as String? ?? 'photo'; type = params['type'] as String? ?? 'photo';
} }
// 使用 STILL_IMAGE_CAMERA / VIDEO_CAMERA 打开系统相机应用
// 而非 IMAGE_CAPTURE / VIDEO_CAPTURE 的捕获模式
final String action = type == 'video' final String action = type == 'video'
? 'android.media.action.VIDEO_CAPTURE' ? 'android.media.action.VIDEO_CAMERA'
: 'android.media.action.IMAGE_CAPTURE'; : 'android.media.action.STILL_IMAGE_CAMERA';
final intent = AndroidIntent(action: action); final intent = AndroidIntent(action: action);
await intent.launch(); await intent.launch();
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!