【问题标题】:Android - Taking photos/video and saving them with a custom name to a custom destination via Intent work on some devices only why?Android - 拍摄照片/视频并通过 Intent 使用自定义名称将它们保存到自定义目的地仅在某些设备上工作,为什么?
【发布时间】:2013-04-12 16:13:23
【问题描述】:

这是我用来创建 Intent 的代码:

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 (Android 2.3.6) 中不起作用。 它正确拍摄图像,但是当它返回 onActivityResult 时没有任何反应。经过一些测试,我发现它没有显示任何内容,因为图像保存在 DCIM/Camera 文件夹而不是图片文件夹中,所以我做错了什么?。

【问题讨论】:

    标签: android android-camera-intent


    【解决方案1】:

    我遇到了同样的问题,在某些手机上它可以正常工作而其他手机却没有,我在此链接中找到了我的解决方案,希望对您有所帮助:

    Deleting a gallery image after camera intent photo taken

    【讨论】:

      猜你喜欢
      • 2012-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-25
      • 1970-01-01
      相关资源
      最近更新 更多