在Redmi mobile中选择多个图像形式库

时间:2018-04-30 09:51:28

标签: android android-layout android-gallery

以下代码无法在 Redmi 4A 中工作...它正在使用最大设备它只能使用Redmi 4A ..我不知道它正在投掷 Nullpointer例外

错误:

  

Exeception:出错了java.lang.NullPointerException:   尝试调用虚方法' int   android.content.ClipData.getItemCount()'在空对象引用上

  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);
        }

这是 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);
    }

0 个答案:

没有答案