【发布时间】:2013-09-20 17:22:42
【问题描述】:
我正在制作一个 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())));
【问题讨论】:
-
这是因为在 Nexus 7 和三星 Galaxy S4 Google 版等设备上,它们没有外部卡。他们有模仿的。因此,该系统旨在将其存储在虚假的外部位置。
-
@JaySnayder:不是真的。 “外部”!=“可移动”。
-
简而言之,没有。您不能以任何 API 支持的方式执行此操作。
-
@CommonsWare 不,这并不意味着可移动,但它确实意味着在内部应用程序位置以外的其他位置。您不会将您的应用程序位置写入内部。您正在写信给外部。
-
是不是说明代码没有问题?
标签: android file sd-card android-sdcard