简体   繁体   English

Android-拍摄照片/录像并将其以自定义名称通过Intent保存到自定义目的地仅在某些设备上有效吗?

[英]Android - Taking photos/video and saving them with a custom name to a custom destination via Intent work on some devices only why?

This is the code i use to create the Intent: 这是我用来创建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);
                 }

And this is the method that returns the file with custom name and location: 这是返回带有自定义名称和位置的文件的方法:

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;

    }

And this is my inActivityResult method that i use: 这是我使用的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));
}

All this methods works on devices like: Motorola Xoom, Motorola Droid, Razor, Some Samsung devices but in Samsung Galaxy Ace s5830m (Android 2.3.6) for example does not work. 所有这些方法都可以在以下设备上使用:Motorola Xoom,Motorola Droid,Razor,某些Samsung设备,但在Samsung Galaxy Ace s5830m(Android 2.3.6)中则无法使用。 It take the images correctly but when it returns to onActivityResult nothing happens. 它可以正确拍摄图像,但是当它返回到onActivityResult时,什么也没有发生。 After some test i found that it do not display anything because the image is saved on DCIM/Camera folder and not on Pictures folder, so what i am doing wrong?. 经过一些测试后,我发现它不显示任何内容,因为图像保存在DCIM / Camera文件夹而不是Pictures文件夹中,所以我在做什么错?

I had the same issue that in some phone it was working and for others doesn't, I found my solution in this link I hope this help you: 我遇到了同样的问题,即在某些电话中它可以正常工作,而对于其他电话则不能,我在此链接中找到了解决方案,希望对您有所帮助:

Deleting a gallery image after camera intent photo taken 拍摄相机意图照片后删除图库图像

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM