Android-在某些设备上拍摄照片/视频,并使用自定义名称将其保存到自定义目的地。为什么?

Android-在某些设备上拍摄照片/视频,并使用自定义名称将其保存到自定义目的地。为什么?,android,android-camera-intent,Android,Android Camera Intent,这是我用来创建意图的代码: try { file = createImageFile(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if(file!= n

这是我用来创建意图的代码:

try {
                    file = createImageFile();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                 if(file!= null)
                 {

                    Log.d(Tag,"absolute path: "+imageAbsolutePath);
                    Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                    i.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(file));        
                    startActivityForResult(i, TAKE_PICTURE);
                 }
这是返回具有自定义名称和位置的文件的方法:

private File createImageFile() throws IOException {

      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
      String currentDate = sdf.format(new Date());

      SimpleDateFormat sdf2 = new SimpleDateFormat("HH:mm:ss");
      String currentTime = sdf2.format(new Date());
      String timeArray[] = currentTime.split(":");

      String imageName = currentDate+" "+timeArray[0]+"-"+timeArray[1]+"-"+timeArray[2];

   // create a File object for the parent directory
   File Pictures = new File(Environment.getExternalStorageDirectory()+File.separator+"Pictures");
   // have the object build the directory structure, if needed.
   if (!Pictures.exists()) {
       Pictures.mkdirs();
       Log.d(Tag,"Pictures folder created: "+Pictures);
       }else
       {
           Log.d(Tag,"Pictures folder Already Exists: "+Pictures);
       }

       // File image = File.createTempFile(imageName,".jpg",Pictures);
   File image = new File (Pictures,imageName+".jpg" );
        Log.d(Tag,"This is Image name: "+ imageName);
        imageAbsolutePath = image.getAbsolutePath();

        return image;

    }
这是我使用的inActivityResult方法:

case TAKE_PICTURE:
             if(resultCode == RESULT_OK)
                {
                 galleryAddPic();
                    Bitmap imgBitmap=null;

                    try
                        {
                        imgBitmap = lessResolution(imageAbsolutePath);                                             

                        }catch (Exception e)                             
                        {
                            e.printStackTrace();
                        }
                        if (imgBitmap!=null)
                        {
                            images.add(imgBitmap);
GridView grid = (GridView) findViewById(R.id.grid_view);
grid.setAdapter(new ImageAdapter(this));
}
所有这些方法都适用于诸如摩托罗拉Xoom、摩托罗拉Droid、Razor等设备,但在三星Galaxy Ace s5830m(安卓2.3.6)等设备中不起作用。
它可以正确地拍摄图像,但当它返回到OnActivity时,结果什么也没有发生。经过一些测试,我发现它没有显示任何内容,因为图像保存在DCIM/Camera文件夹中,而不是图片文件夹中,所以我做错了什么?

我遇到了相同的问题,在某些手机中它正常工作,而在其他手机中则没有,我在这个链接中找到了我的解决方案,我希望这能帮助您: