-1

I am using this code to pick image from gallery it was working but now it has stopped working

(items[item].equals("Change from Library")) {
                        Intent i = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                        startActivityForResult(i, SELECT_FILE); 

onActivity Result

 Uri selectedImage = data.getData();
                String url = "";
                String pictureDirectoryPath= Functions.getRealPathFromURI(getActivity(),selectedImage()); 

Here is my Android monitor log when the button to pick image gallery is clicked

58.819 8995-8995/com.example.sharique.loginapp W/EGL_genymotion: eglSurfaceAttrib not implemented
05-01 08:39:00.375 557-683/system_process W/InputMethodManagerService:     Window already focused, ignoring focus gain of:     com.android.internal.view.IInputMethodClient$Stub$Proxy@52921524 attribute=null,      token = android.os.BinderProxy@5296999c
Shariq
  • 51
  • 1
  • 6

1 Answers1

1

try this :

Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
                    photoPickerIntent.setType("image/*");
                    startActivityForResult(photoPickerIntent, 500);

onActivity Result

Uri selectedImageUri = imageReturnedIntent.getData();
String mPath = getPath(selectedImageUri);

getPath() method

public String getPath(Uri uri) {
        String[] projection = {MediaStore.MediaColumns.DATA};
        Cursor cursor = getActivity().managedQuery(uri, projection, null, null, null);
        int column_index = cursor
                .getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
        cursor.moveToFirst();
        String imagePath = cursor.getString(column_index);

        return cursor.getString(column_index);
    }

if your target and compile sdk higher than lollipop then you have to add request permission code refer this link

Bhupat Bheda
  • 1,968
  • 1
  • 8
  • 13