Android-拍照暂时使用相机意图

时间:2015-02-18 23:41:08

标签: android android-intent camera

我正在使用内置相机意图拍照,而我的应用只需要图像来创建一个位图。是否可以避免将图像保存到图库而无需创建自己的自定义相机?这是我目前拍摄照片的代码。

public void open() {
    Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(intent, 1);
}
static Bitmap bp;

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    bp = (Bitmap) data.getExtras().get("data");
    onNavigationDrawerItemSelected(currentPosition);

    }

1 个答案:

答案 0 :(得分:1)

Nop,但您可以将其删除,请尝试以下代码:

 private void DeletePicTaken(){
            final String[] imageColumns = { BaseColumns._ID, MediaColumns.DATA };
            final String imageOrderBy = BaseColumns._ID + " DESC";
            Cursor imageCursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, imageColumns, null, null, imageOrderBy);
            if(imageCursor.moveToFirst()){
                //int id = imageCursor.getInt(imageCursor.getColumnIndex(MediaStore.Images.Media._ID));
                String fullPath = imageCursor.getString(imageCursor.getColumnIndex(MediaColumns.DATA));
                //imageCursor.close();
                File file = new File(fullPath);
                file.delete();
            }


        } 

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    bp = (Bitmap) data.getExtras().get("data");
    onNavigationDrawerItemSelected(currentPosition);
    DeletePicTaken();
    }