我正在制作一个 android 应用程序,我想将下载的图像存储到 sdcard 或外部存储中。我面临的问题是,在某些手机上,图像存储在 sdcard 上,而在某些手机中,图像存储在内部存储器中,特别是在 Galaxy S4 等三星设备中。有关 S4 中的文件路径,请参阅附件图像。
File wallpaperDirectory = new File(
Environment.getExternalStorageDirectory()
+ "/TestApp/");
wallpaperDirectory.mkdirs();
FileOutputStream out = new FileOutputStream(Environment
.getExternalStorageDirectory().toString()
+ "/TestApp/" + secret + ".jpg");
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
Toast.makeText(
getApplicationContext(),
"Wallpaper saved sucessfully \n"
+ Environment.getExternalStorageDirectory()
.toString() + "/TestApp/" + secret
+ ".jpg", Toast.LENGTH_SHORT).show();
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://"
+ Environment.getExternalStorageDirectory())));