gpt4 book ai didi

android - Android 6.0 未经许可抓拍图片

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:21:59 26 4
gpt4 key购买 nike

我需要让用户使用 Android 6.0 拍照(从图库或相机应用)。

因为我不需要控制相机,所以我想使用此处描述的 Intent :

However, if you don't need such control, you can just use an ACTION_IMAGE_CAPTURE intent to request an image. When you start the intent, the user is prompted to choose a camera app (if there isn't already a default camera app), and that app takes the picture. The camera app returns the picture to your app's onActivityResult() method.

https://developer.android.com/preview/features/runtime-permissions.html

但是对于这个ACTION_IMAGE_CAPTURE,你需要填充额外的"MediaStore.EXTRA_OUTPUT",它是一个临时文件的Uri(没有这个参数我将只有一个缩略图)。这个临时文件必须在外部存储中(相机应用程序可以访问)。您需要WRITE_EXTERNAL_STORAGE权限才能在外部存储上创建文件。

因此,如果没有 android.permission.CAMERAandroid.permission.WRITE_EXTERNAL_STORAGE 权限,则无法通过 native 对话框/应用程序捕获图像。对吗?

谢谢

最佳答案

试试这个:

Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(getActivity().getApplicationContext().getExternalFilesDir(android.os.Environment.DIRECTORY_PICTURES).getAbsolutePath() + File.separator + "yourPicture.jpg");
Uri uri = Uri.fromFile(file);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, url);

在这种情况下,这使您可以访问相机应用程序可写的“外部”存储,但这些文件只能从您的应用程序中看到。要了解更多关于 android 中存储空间的信息,请参阅 https://www.youtube.com/watch?v=C28pvd2plBA

希望对你有帮助!

关于android - Android 6.0 未经许可抓拍图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32462725/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com