Intent.ACTION_PICK behaves differently

前端 未结 2 1464
鱼传尺愫
鱼传尺愫 2021-01-26 13:28

I am using following code to pick an image from the gallery. When I test it with Samsung Galaxy S4, it directly goes to Gallery that is what I want actually.

BUT, when

2条回答
  •  鱼传尺愫
    2021-01-26 13:42

    if you want Gallery then

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

    please use for api 19 or above

    if (Build.VERSION.SDK_INT < 19) {
                            Intent intent = new Intent();
                            intent.setType("image/jpeg");
                            intent.setAction(Intent.ACTION_GET_CONTENT);
    
                            startActivityForResult(Intent.createChooser(intent,
                                    "Select image to promote"),
                                    GALLERY_INTENT_CALLED);
    
                        } else {
                            Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
                            intent.addCategory(Intent.CATEGORY_OPENABLE);
                            intent.setType("image/jpeg");
                            startActivityForResult(intent,
                                    GALLERY_KITKAT_INTENT_CALLED);
                        }
    

提交回复
热议问题