0

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);
    }
    }
}
sami
  • 3
  • 6
  • have a look at this http://stackoverflow.com/questions/27113357/getrealpathfromuri-always-get-null-result – sachithkn Jul 24 '15 at 21:41

1 Answers1

0

if you try give image of your gallery try this

protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) { Uri selectedImage = data.getData(); String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getContentResolver().query(selectedImage,filePathColumn, null, null, null); cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex(filePathColumn[0]); String picturePath = cursor.getString(columnIndex); cursor.close(); ImageView imageView = (ImageView) findViewById(R.id.imgView); imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath)); } }

but firts

Intent i = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

startActivityForResult(i, RESULT_LOAD_IMAGE);