I want to load an image from an external folder of my system to my android application. I use the following code, but the image is not displaying. When I debugged it, the Bitmap object 'bitmap' is shown as null. How can I solve this problem?
ImageView img=(ImageView)findViewById(R.id.myImage);
String fname="C:/Users/Public/Pictures/Garden.jpg";
Bitmap bitmap = BitmapFactory.decodeFile(fname);
img.setImageBitmap(bitmap);
My actual need is my andorid application (on real device) should display some images which is stored into one computer. The admin of this application will upload some images to a specific folder in that computer. And the android application will access these images using IP a开发者_运维技巧ddress, and will display these images. If these images should be pushed to sdcard path, then how can i do it at runtime?
Please help me..
Thank you to all..
An "external folder"? What is that? Android only has access to its internal file system (i.e. the internal storage, and the SD card, and whatever else you may have mounted via the Linux operating system). Using a Windows path is definitely never going to work. Where is that data supposed to be coming from?
You need to use a proper UNIX-style path that either points to the phone's internal storage, or the SD card, and the path needs to be accessible by your application.
You cannot access you system file. Check this link
If you are trying to access SDcard you can use the following
ImageView img=(ImageView)findViewById(R.id.myImage);
File imgFile = new File(“/sdcard/Images/image.jpg”);
if(imgFile.exists()){
Bitmap bitmap = BitmapFactory.decodeFile(imgFile);
myImage.setImageBitmap(bitmap );
}
You can't access files that are on your computer from android (emulator or phone). you have to consider your application as running independently from the rest.
if you really don't want to place your image inside the drawable folder of android (and access it using R.drawable.imagename then you need to push your image onto the sdcard of your phone/emulator and open it using the sdcard path
精彩评论