Android意图-将uri传递给摄像头

Android意图-将uri传递给摄像头,android,android-intent,Android,Android Intent,我正在尝试测试与通过相机拍摄图像相关的功能。文档中说,如果相机将保存图像,则可以将URI作为额外信息传递 我尝试了以下方法: // image1 doesn't exist File file = new File(getFilesDir() + "/image1"); Uri uri = Uri.fromFile(file); Intent i = new Intent(); i.setAction(MediaStore.ACTION_IMAGE_CAPTURE); i.putExtra(M

我正在尝试测试与通过相机拍摄图像相关的功能。文档中说,如果相机将保存图像,则可以将URI作为额外信息传递

我尝试了以下方法:

// image1 doesn't exist
File file = new File(getFilesDir() + "/image1");
Uri uri = Uri.fromFile(file);

Intent i = new Intent();
i.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(MediaStore.EXTRA_OUTPUT, uri);

if (i.resolveActivity(getPackageManager()) != null) {
     startActivityForResult(i, 1337);
}
我正在尝试将图像作为名为image1的文件放置在我的文件目录中。我正在genymotion虚拟机上测试这个。我已经在return Intent中测试过将图像作为位图获取,但是当我使用上述方法时,当我在拍照后单击“完成”时,相机应用程序会卡住

我猜这与URI权限有关。我是否需要像在数据共享中那样在intent中添加一些权限

编辑

我尝试按照这些操作,但我想将照片保存在我的应用程序目录中,因此我尝试了以下操作,但无效(该应用程序具有照相机权限):

我也有onActivityResult(),但它没有用,因为摄像头应用程序如上所述被卡住了


另外,还有一个问题:当我在测试应用程序中没有摄像头权限时,我仍然可以调用摄像头并在intent extra中获取位图,这是怎么回事?这是genymotion VM特有的吗?

请确保您对清单拥有这些权限

 <uses-permission android:name="android.permission.CAMERA" />
 <uses-feature android:name="android.hardware.camera" />
 <uses-feature android:name="android.hardware.camera.autofocus" />
 <uses-permission android:name="android.permission.CAMERA" />
 <uses-feature android:name="android.hardware.camera" />
 <uses-feature android:name="android.hardware.camera.autofocus" />
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == 1) {
        if(resultCode == RESULT_OK){
            String result=data.getStringExtra("result");
        }
        if (resultCode == RESULT_CANCELED) {
            //Write your code if there's no result
        }
    }
}//onActivityResult