android – 如何将图像保存到外部存储器而不是保存在内部

android – 如何将图像保存到外部存储器而不是保存在内部,第1张

概述我不明白为什么人们说这是保存在外部存储器,因为当我使用这个代码,我签入我的SD卡没有文件 代码这个 OutputStream imageFileOS; int imageNum = 0; Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 我不明白为什么人们说这是保存在外部存储器,因为当我使用这个代码,我签入我的SD卡没有文件

代码这个

OutputStream imagefileOS;        int imageNum = 0;        Intent imageIntent = new Intent(androID.provIDer.MediaStore.ACTION_IMAGE_CAPTURE);        file imagesFolder = new file(Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES),"Punch");        if(!imagesFolder.exists()){            imagesFolder.mkdirs(); // <----        }        String filename = "image_" + String.valueOf(imageNum) + ".jpg";        file output = new file(imagesFolder,filename);        while (output.exists()){            imageNum++;            filename = "image_" + String.valueOf(imageNum) + ".jpg";            output = new file(imagesFolder,filename);        }        Uri uriSavedImage = Uri.fromfile(output);        imageIntent.putExtra(MediaStore.EXTRA_OUTPUT,uriSavedImage);

当我运行代码并检查时,它有“内存/图片/打孔/图像_0.jpg”中的文件
但在SD卡中看不到(SD卡=外部存储卡16 GB)
请帮我 ..

解决方法 我认为你对getExternalStorageDirectory的作用感到困惑.

它获取由设备制造商指定的主存储目录.这通常是“sdcard”.注释中指定的“External_sd”实际上是辅助存储目录,不会在给定方法中返回.

这仍然不是受保护的内部存储,并且可以在连接时由Pcs安装和访问.

来自androID文档:

Note: don’t be confused by the word “external” here. This directory can better be thought as media/shared storage. It is a filesystem that can hold a relatively large amount of data and that is shared across all applications (does not enforce permissions). Traditionally this is an SD card,but it may also be implemented as built-in storage in a device that is distinct from the protected internal storage and can be mounted as a filesystem on a computer.

总结

以上是内存溢出为你收集整理的android – 如何将图像保存到外部存储器而不是保存在内部全部内容,希望文章能够帮你解决android – 如何将图像保存到外部存储器而不是保存在内部所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1126787.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存