在模拟genymotion中保存相机图片不起作用

时间:2016-02-14 00:14:54

标签: java android android-studio genymotion

我无法使用Genymotion模拟器在SD卡中保存图片。

为图像创建文件的代码

private File createImageFile() throws IOException {
    // Create an image file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    String imageFileName = "JPEG_" + timeStamp + "_";
    //File storageDir = Environment.getExternalStoragePublicDirectory(
    //Environment.DIRECTORY_PICTURES);
    File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
    File image = File.createTempFile(
                imageFileName,  /* prefix */
                ".jpg",         /* suffix */
                storageDir      /* directory */
        );
        mCurrentPhotoPath = "file:" + image.getAbsolutePath();

    // Save a file: path for use with ACTION_VIEW intents

    Toast.makeText(AddPhotoActivity.this, mCurrentPhotoPath + "file", Toast.LENGTH_SHORT).show();
    return image;

}

上述功能没有返回任何内容。以下功能用于启动相机意图并点击图片。

private void dispatchTakePictureIntent() {
   // Toast.makeText(AddPhotoActivity.this, "Hello", Toast.LENGTH_SHORT).show();

    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // Ensure that there's a camera activity to handle the intent
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        // Create the File where the photo should go
        File photoFile = null;
        try {
            photoFile = createImageFile();
        } catch (IOException ex) {
            // Error occurred while creating the File
        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                    Uri.fromFile(photoFile));
            startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
        }
    }
}

问题是File.createTempFile()函数中的问题。我猜。

0 个答案:

没有答案