【问题标题】:setting ImageView from image stored in sdcard in higher version of android not working在更高版本的android中从存储在sdcard中的图像设置ImageView不起作用
【发布时间】:2013-09-15 13:12:54
【问题描述】:
Toast.makeText(this, Environment.getExternalStorageDirectory(),
    Toast.LENGTH_LONG).show();

File file = new File(Environment.getExternalStorageDirectory() +
    "/whatsupv2/abc.jpg");

Bitmap mybitmap = BitmapFactory.decodeFile(file.getAbsolutePath());

imageView.setImageURI(Uri.fromFile(file));

上面的代码适用于 android 3.3,但不适用于 4.1.2,我们有两个存储目录...我检查了 abc.jpg 是否存在于 dir.. 并且给出的路径是正确的.. 但 imageview 只显示一个白屏..

【问题讨论】:

  • 你解决了这个问题吗?我也面临同样的问题。

标签: android file bitmap imageview


【解决方案1】:

但在 4.1.2 中我们有两个存储目录

所有 Android 设备中只有一个外部存储目录,至少在 Android 4.3 之前是这样。

首先,确保图片在官方外部存储位置。

其次,使用new File(Environment.getExternalStorageDirectory(), "/whatsupv2/abc.jpg")而不是字符串连接。

第三,要么使用decodeFile() setImageURI(),不能同时使用。

第四,检查 LogCat 是否有任何消息。

【讨论】:

    猜你喜欢
    • 2023-03-23
    • 1970-01-01
    • 2020-08-15
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    • 2011-09-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多