I am trying to display images clicked from camera or selected from gallery in a gridview. The images clicked from camera are working fine but I am not able to fetch images from gallery and display in gridview. Below is the code I am using:
Here "mCurrentPhotoPath" is the File path to the last image captured
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == REQUEST_TAKE_PHOTO && resultCode == RESULT_OK)
{
// Save Image To Gallery
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE );
File f = new File(mCurrentPhotoPath );
Uri contentUri = Uri.fromFile(f);
mediaScanIntent.setData(contentUri);
this.sendBroadcast(mediaScanIntent);
// Add Image Path To List
myList.add( mCurrentPhotoPath);
// Refresh Gridview Image Thumbnails
gridview.invalidateViews();
}
else if (requestCode == 2 && resultCode == RESULT_OK)
{
//**New some suggestion here**
Uri selectedImageUri = data.getData();
String s = getRealPathFromURI(selectedImageUri);
myList.add(s);
}
}
}