开发者

accessing files on SD card in android

I want to display image from a sd card into image view

Following code works in emulator but does not work on actual phone

File f = new File(imgPath);

if (f.exists()) {
   imgView.setImageDra开发者_开发知识库wable(Drawable.createFromPath("/mnt/sdcard/abc.jpg") ));

} else {

   imgView.setImageResource( R.drawable.image_abasent);

}

abc.jpg is put in emulator sd card sdk folder using DDMS I have also put abc.jpg directly on SD card through USB connection

I have added following permission too in the manifest file (but while installing from apk permission is not asked though)

uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"

Still on phone the desired image is not accessible. What else is to be added or modified?


Please paste your manifest and also for accessing the SDCard you must use Environment.getExternalStorageDirectory() since /mnt/sdcard/ would be a hardcoded solution and may not work on some devices or android builds.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜