Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何从SD卡中检索图像_Android_Android Sdcard - Fatal编程技术网

Android 如何从SD卡中检索图像

Android 如何从SD卡中检索图像,android,android-sdcard,Android,Android Sdcard,我有这个代码从SD卡中检索图像。但是它在ImageView中没有显示任何图片。我确信SD卡上有图像 File f = new File("/mint/sdcard/e.jpg"); Bitmap bitmap = BitmapFactory.decodeFile(f.getAbsolutePath()); Toast.makeText(this, bitmap + "", 3).show(); bmImage.setImageBitmap(bitmap); 像这样改变它 File f = n

我有这个代码从SD卡中检索图像。但是它在
ImageView
中没有显示任何图片。我确信SD卡上有图像

File f = new File("/mint/sdcard/e.jpg");

Bitmap bitmap = BitmapFactory.decodeFile(f.getAbsolutePath());
Toast.makeText(this, bitmap + "", 3).show();
bmImage.setImageBitmap(bitmap);
像这样改变它

File f = new File("/mnt/sdcard/e.jpg");   
Bitmap bitmap = BitmapFactory.decodeFile(f.getAbsolutePath());
bmImage .setImageBitmap(bitmap);

它不是
mint
Its
mnt
。把你的台词写成

File f = new File("/mnt/sdcard/e.jpg");
您不必使用
“/mnt/sdcard/e.jpg”
。您必须使用此方法:

Environment.getExternalStorageDirectory().toString()

因为它将返回外部目录的正确路径。制造商可以将其重命名为其他名称,因此您必须使用上述方法。

最好使用以下方法:

File sdcard = Environment.getExternalStorageDirectory();

File f = new File(sdcard+"/e.jpg");

现在它可以在所有Android手机上运行了

its not
mint
its
mnt
在写了之后它仍然不工作……你在logcat上收到任何错误消息了吗?是的,它的mnt谢谢……它现在可以工作了……你可能应该接受@vini下面的答案,因为他是第一个参加舞会的人。:)向OP提及所做的更改(尽管您在上面发表了评论)
File sdcard = Environment.getExternalStorageDirectory();

File f = new File(sdcard+"/e.jpg");