【教程】autojs使用Intent打开相机拍照并指定存储路径

转载请注明出处:小锋学长生活大爆炸[xfxuezhang.cn]

var photoPath = "/sdcard/a.jpg";
var photoFile = new java.io.File(photoPath);
if (!photoFile.exists()) {photoFile.getParentFile().mkdirs();}
try {
    photoFile.createNewFile();
} catch (e) {
    toast("创建文件失败: " + e);
    return;
}
// 获取文件Uri
var photoURI = android.net.Uri.fromFile(photoFile);
// 创建Intent启动相机
var intent = new android.content.Intent("android.media.action.IMAGE_CAPTURE");
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, photoURI);
// 启动相机应用
app.startActivity(intent);

注意要给一下“相机”权限,选“仅使用中可用”或者“总是允许”都可以,“每次询问”可能不大行。

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-02-13 10:04:04       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-02-13 10:04:04       106 阅读
  3. 在Django里面运行非项目文件

    2024-02-13 10:04:04       87 阅读
  4. Python语言-面向对象

    2024-02-13 10:04:04       96 阅读

热门阅读

  1. Linux 常用的命令

    2024-02-13 10:04:04       51 阅读
  2. 函数高级(C++)

    2024-02-13 10:04:04       52 阅读
  3. 2024/2/12 图的基础知识 2

    2024-02-13 10:04:04       62 阅读
  4. 如何用 docker 部署程序?

    2024-02-13 10:04:04       63 阅读
  5. Junit常用断言

    2024-02-13 10:04:04       52 阅读
  6. 2.12作业

    2024-02-13 10:04:04       48 阅读
  7. 记录 | C++ cout.setf(ios::fixed)

    2024-02-13 10:04:04       54 阅读
  8. k8s搭建容器云平台

    2024-02-13 10:04:04       49 阅读
  9. sqlserver 触发器

    2024-02-13 10:04:04       53 阅读