Android ACTION_IMAGE_CAPTURE Intent

后端 未结 14 2185
被撕碎了的回忆
被撕碎了的回忆 2020-11-22 02:04

We are trying to use the native camera app to let the user take a new picture. It works just fine if we leave out the EXTRA_OUTPUT extra and returns the small B

14条回答
  •  庸人自扰
    2020-11-22 02:57

    to have the camera write to sdcard but keep in a new Album on the gallery app I use this :

     File imageDirectory = new File("/sdcard/signifio");
              String path = imageDirectory.toString().toLowerCase();
               String name = imageDirectory.getName().toLowerCase();
    
    
                ContentValues values = new ContentValues(); 
                values.put(Media.TITLE, "Image"); 
                values.put(Images.Media.BUCKET_ID, path.hashCode());
                values.put(Images.Media.BUCKET_DISPLAY_NAME,name);
    
                values.put(Images.Media.MIME_TYPE, "image/jpeg");
                values.put(Media.DESCRIPTION, "Image capture by camera");
               values.put("_data", "/sdcard/signifio/1111.jpg");
             uri = getContentResolver().insert( Media.EXTERNAL_CONTENT_URI , values);
                Intent i = new Intent("android.media.action.IMAGE_CAPTURE"); 
    
                i.putExtra(MediaStore.EXTRA_OUTPUT, uri);
    
                startActivityForResult(i, 0); 
    

    Please note that you will need to generate a unique filename every time and replace teh 1111.jpg that I wrote. This was tested with nexus one. the uri is declared in the private class , so on activity result I am able to load the image from the uri to imageView for preview if needed.

提交回复
热议问题