我对外部存储的概念很困惑。我在下面有一段代码,我想将我的位图绘图保存到内部存储中。
FileOutputStream outStream = null;
File filePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File dir = new File(filePath.getAbsolutePath(), "/Test_Folder");
if (dir == null || !dir.mkdirs()) {
Log.e("File", "Directory not created");
Toast.makeText(getActivity(), "Directory not created", Toast.LENGTH_SHORT).show();
}
String fileName = String.format("%d.jpg", System.currentTimeMillis());
File outFile = new File(dir, fileName);
try {
outStream = new FileOutputStream(outFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
outStream.flush();
outStream.close();
Toast.makeText(getActivity(), "Saved to Gallery", Toast.LENGTH_SHORT).show();
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
所以在我的三星 Android 中,它保存到“内部存储器”中。对于 Android Studio 模拟器,它保存到“SD 卡”中,对于其他一些设备,它会记录或吐司“目录未创建”。
我读过一些关于存储/模拟/0 的非常古老的帖子是选择的“默认存储”吗?我如何定位到一个非常具体的存储类型,为什么有时其他设备不写入?