views:

388

answers:

2

Greetings:

I am writing an Android app that includes an ImageView. The image to be included in the view resides on the local app directory of the emulator. The image is not being displayed in the view. The relavent XML and method used to display the image are given below.

The image file is a "png" format file and is able to be opened from the local app directory. The path returned by getFilesDir() includes the full path, "/data/data/net.vitalrecord.android/files." This path designation does not exist on the development system but does exists when DDMS File Explorer is used.

Any help with this problem is greatly appreciated.

Thanks.

LAYOUT XML: ......

<ImageView

android:id="@+id/picture" android:layout_width="wrap_content" android:layout_height="wrap_content"/> android:layout_x="100px" android:layout_y="100px" />

Method: public void checkFilesExists() {

.....

try {
 Context context = getApplicationContext();
 FILENAME = getString(R.string.MedicalImage);
 fis = openFileInput(FILENAME);
 int size = fis.available();
 byte[] buffer = new byte[size];
 fis.read(buffer);
 fis.close();
 setContentView(R.layout.medtogoimage);
    ImageView iv = (ImageView)findViewById(R.id.picture);
    String imagePath = context.getFilesDir() + "/" + FILENAME;
    Drawable d = Drawable.createFromPath(imagePath);
    iv.setImageDrawable(d);
    medtogo.setbMedicalImageFileExists(true);
} catch (IOException e) {
  medtogo.setbMedicalImageFileExists(false);
}
A: 

You should put images inside the res/drawable folder. Then you can get its reference with the R class, or assign it to the ImageView from layout xml file.

jaxvy
The png image is being stored in the local app directory since it is being retrieved from a remote server as a stream along with other data elements. The drawable folder is a read-only folder.But thanks for the suggeston.
Roy
A: 

Did you try setting the mode to MODE_WORLD_READABLE?

Chris
No, I have not tried "MODE_WORLD_READABLE." Actually, I do not want the world to read the image.The application can read the image as shown by the code I provided above.I believe the problem lies with the method, "getFilesDir()". Using debug, it returns an absolute path of "/data/data/net.vitalrecord.android". This absolute path does not exist on the development system.However, when the Eclipse Android add-on is used to invoke File Explorer of DDMS, the folder /data/data/... shows along with the png image. I suspect the local app folder is embedded in the emulator context.
Roy