Skip to content Skip to sidebar Skip to footer

Start Activity For Result Not Working

I'm using start Activity result for starting a new activity to select a image from gallery and it will return a image path to my main activity to , so that it will insert image in

Solution 1:

The intent is wrong, try this:

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.setType("image/*");

Solution 2:

Start Activity

private static final int PICK_IMAGE = 1;
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE);

Take Result

 @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) 
  {
    if(requestCode == PICK_IMAGE && data != null && data.getData() != null)
     {
       Uri _uri = data.getData();
       //User had pick an image.
       Cursor cursor = getContentResolver().query(_uri, new String[] {     
       android.provider.MediaStore.Images.ImageColumns.DATA }, null, null, null);
       cursor.moveToFirst();

       //Link to the image
       final String imageFilePath = cursor.getString(0);

       cursor.close();
     }
    super.onActivityResult(requestCode, resultCode, data);

}


Post a Comment for "Start Activity For Result Not Working"