Pick multiple images form gallery in Redmi mobile

我是研究僧i 提交于 2020-01-16 08:36:14

问题


Below code is not working in Redmi 4A...it's working maximum devices it not working only Redmi 4A..i donot know it's throwing Nullpointer exception

Error:

Exeception: something went wrongjava.lang.NullPointerException: Attempt to invoke virtual method 'int android.content.ClipData.getItemCount()' on a null object reference

  if (Build.VERSION.SDK_INT < 19) {
            Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            galleryIntent.setType("video/*, image/*");  // galleryIntent.setType("image/* video/*");
            galleryIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
            startActivityForResult(Intent.createChooser(galleryIntent,"Select Picture"), PICK_IMAGE_MULTIPLE);
        } else {
            Toast.makeText(PreviewImages.this,"WEdfsdfsdfdsfsfdsf",Toast.LENGTH_SHORT).show();
            Intent galleryIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            galleryIntent.addCategory(Intent.CATEGORY_OPENABLE);
            galleryIntent.setType("*/*");
            galleryIntent.putExtra(Intent.EXTRA_MIME_TYPES, new String[] {"image/*", "video/*"});
            galleryIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
            startActivityForResult(Intent.createChooser(galleryIntent,"Select Picture"), PICK_IMAGE_MULTIPLE);
        }

Here is OnActivityResult

  @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        try {
            // When an Image is picked
            if (requestCode == PICK_IMAGE_MULTIPLE && resultCode == RESULT_OK
                    && null != data) {
                // Get the Image from data
                Log.e("previewimages"," **onActivityResult   ");
                String[] filePathColumn = {     MediaStore.Images.Media.DATA };

                    if(data.getData()!=null){
                    Log.e("previewimages"," **single  image selections   ");
                    String[] files = new String[1];
                    Log.e("printuri result","****oneimg    "+data.getData());
                    String  realPath = ImageFilePath.getPath(PreviewImages.this, data.getData());
                    files[0]  = realPath;

                    ImagepathModel imagepathModel = new ImagepathModel();
                    imagepathModel.setFilepath(realPath);
                    arrayList_copyfilepath.add(imagepathModel);

                    selectedimag_adapter.notifyDataSetChanged();
                    preview_playimagee.setEnabled(true);
                    preview_playimagee.setVisibility(View.VISIBLE);
                    displayFirstImages();
                    removepos =0;
                    if (myAnim !=null)
                        tv_add_sticker.startAnimation(myAnim);

                } else {
                    Log.e("previewimages"," **mutiple image selections   "+data.getClipData() +"   ==  "+data.getClipData().getItemCount());
                    if (data.getClipData() != null) {
                        ClipData mClipData = data.getClipData();
                        String[] files = new String[ mClipData.getItemCount()];
                        for (int i = 0; i < mClipData.getItemCount(); i++) {

                            ClipData.Item item = mClipData.getItemAt(i);
                            String  realPath = ImageFilePath.getPath(PreviewImages.this, item.getUri());

                            ImagepathModel imagepathModel = new ImagepathModel();
                            imagepathModel.setFilepath(realPath);
                            arrayList_copyfilepath.add(imagepathModel);

                            final File file = new File(realPath);
                            if (file.exists()) {

                                Log.e("fileexistes","*****          "+  "   File is existss      "  + realPath);
                            }else {
                                Log.e("fileexistes","*****          "+  "   Nofilefounds      ");

                            }

                           // preview_playimagee.setImageURI(data.getData());
                            Log.e("filepaths","****uris    "+item.getUri());
                            Log.e("filepaths","multipleimages          "+"    realpath \n "+realPath);


                        }


                         preview_playimagee.setEnabled(true);
                         preview_playimagee.setVisibility(View.VISIBLE);
                         selectedimag_adapter.notifyDataSetChanged();
                         displayFirstImages();
                         removepos = 0;
                        if (myAnim !=null)
                         tv_add_sticker.startAnimation(myAnim);
                     }
                }
            } else {
                if (arrayList_copyfilepath.size() == 0)
                Toast.makeText(this, "Please Select Atleast One Pick",
                        Toast.LENGTH_LONG).show();
            }
        } catch (Exception e) {
            Toast.makeText(this, "Something went wrong", Toast.LENGTH_LONG)
                    .show();
            Log.e("Exeception","something went wrong"+e.toString());
        }
        super.onActivityResult(requestCode, resultCode, data);
    }

来源:https://stackoverflow.com/questions/50098009/pick-multiple-images-form-gallery-in-redmi-mobile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!