Open gallery app from Android Intent

后端 未结 6 1199
难免孤独
难免孤独 2020-11-29 04:30

I\'m looking for a way to open the Android gallery application from an intent.

I do not want to return a picture, but rather just open the gallery to al

6条回答
  •  旧时难觅i
    2020-11-29 05:11

    I hope this will help you. This code works for me.

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

    ResultCode is used for updating the selected image to Gallery View

    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);
    
            if (cursor == null || cursor.getCount() < 1) {
                return; // no cursor or no record. DO YOUR ERROR HANDLING
            }
    
            cursor.moveToFirst();
            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
    
            if(columnIndex < 0) // no column index
                return; // DO YOUR ERROR HANDLING
    
            String picturePath = cursor.getString(columnIndex);
    
            cursor.close(); // close cursor
    
            photo = decodeFilePath(picturePath.toString());
    
            List bitmap = new ArrayList();
            bitmap.add(photo);
            ImageAdapter imageAdapter = new ImageAdapter(
                    AddIncidentScreen.this, bitmap);
            imageAdapter.notifyDataSetChanged();
            newTagImage.setAdapter(imageAdapter);
        }
    

提交回复
热议问题