我正在尝试使用相机意图,使用下面的代码。
public boolean onLongClick(View v) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
return false;
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.i("user prof", "resultcode: "+resultCode);
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
Toast.makeText(this, "Picture was taken", Toast.LENGTH_SHORT).show();
} else if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, "Picture was not taken", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Picture was not taken", Toast.LENGTH_SHORT).show();
}
}
}
相机工作,它打开并让我拍照,但正面按钮不起作用,它不会关闭意图,也不会显示在 logcat 或 Toast 工具中。问题是在按下相机意图中的正按钮时永远不会调用方法“onActivityResult”,另一方面,在按下负按钮时会正确调用它。
我在清单中声明了这些权限
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera.autofocus" />
我怎样才能解决这个问题?
谢谢