Skip to content Skip to sidebar Skip to footer

Storing Image Path From Sdcard In Android

how to store image path into array.as i'm retrieving images dynamically.n listing them.after clicking on one o the image i want to send it to previous activity. how can i store the

Solution 1:

Using GSON library

http://www.mkyong.com/java/how-do-convert-java-object-to-from-json-format-gson-api/

you can create a json string of the image path array then store the json string to preference

http://www.javacodegeeks.com/2011/01/android-quick-preferences-tutorial.html

Storing value in preference can be accessible to all the activities. And from another activity convert json string to array and you can use that array.

OR

You can create a static array in an activity and can use it statically across the activities.

Solution 2:

Try like that:

Your Called Activity:

File f = newFile("/sdcard");
File[] files = f.listFiles();
ArrayList<String> imagesPaths = newArrayList<String>(); // Array to store the images paths@OverridepublicvoidonCheckedChanged(CompoundButton buttonView, boolean isChecked) {

    // TODO Auto-generated method stub
    i=newIntent();
    for(int j=0; j< ch.lenght; j++){
        if(ch[j].isChecked())
        {
             imagePaths.add(f[j].getAbsolutePath());
        }       
    }
    i.putStringArrayListExtra("files", imagePaths);
    setResult(RESULT_OK, i);
    finish();
}

Your Caller Activity:

@OverrideprotectedvoidonActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stubsuper.onActivityResult(requestCode, resultCode, data);

   if(requestCode==1)
   {
       ArrayList<String> paths= data.getStringArrayListExtra("files");
       System.out.println(paths.toString());
  }

}

Solution 3:

case1:
            if(resultCode == RESULT_OK){  
                UriselectedImage= imageReturnedIntent.getData();
                Stringpath= getRealPathFromURI( selectedImage );
                LogMsg.d("PAth "+path);
                Bitmapb= getBitmap(path);
                bitmapList.add(b);
                adapter.notifyDataSetChanged();
            }
        break;

and then;

private String getRealPathFromURI(Uri contentUri) {
           ContentResolverresolver= getContentResolver();
           String[] proj = { MediaStore.Video.Media.DATA };
           Cursorcursor= resolver.query(contentUri, proj, null, null, null);
           intcolumn_index= cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
           cursor.moveToFirst();
           return cursor.getString(column_index);
        }

Post a Comment for "Storing Image Path From Sdcard In Android"