Android 相机意图不返回/锁定
我试图使用 onActivityResult
的意图从相机拍照,但每次拍照时相机都会锁定并且永远不会返回。有什么原因可能会发生这种情况吗?这是我正在使用的代码:
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.v(TAG,"Camera callback: "+Integer.toString(resultCode));
if (requestCode == CAMERA_PIC_REQUEST) {
try{
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
Log.v("Picture view",data.getData().toString());
ImageView image = new ImageView(this);
image.setImageBitmap(thumbnail);
setContentView(image);
}
catch(Exception e){
Log.e(TAG, "something happened");
e.printStackTrace();
}
}
}
这是拍照后的 LogCat 输出:
06-12 19:46:03.881: VERBOSE/camera(443): Start autofocus.
06-12 19:46:04.521: VERBOSE/camera(443): doSnap: mFocusState=1
06-12 19:46:04.721: VERBOSE/camera(443): mAutoFocusTime = 790ms
然后它就锁定并且 onActivityResult
永远不会触发。
感谢您的投入。
I'm trying to take a picture from the Camera using intent with onActivityResult
but every time I take a picture the camera locks up and never returns. Any reason why this might happen? This is the code I'm using:
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.v(TAG,"Camera callback: "+Integer.toString(resultCode));
if (requestCode == CAMERA_PIC_REQUEST) {
try{
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
Log.v("Picture view",data.getData().toString());
ImageView image = new ImageView(this);
image.setImageBitmap(thumbnail);
setContentView(image);
}
catch(Exception e){
Log.e(TAG, "something happened");
e.printStackTrace();
}
}
}
This is the LogCat output after taking a picture:
06-12 19:46:03.881: VERBOSE/camera(443): Start autofocus.
06-12 19:46:04.521: VERBOSE/camera(443): doSnap: mFocusState=1
06-12 19:46:04.721: VERBOSE/camera(443): mAutoFocusTime = 790ms
Then it just locks up and onActivityResult
never fires.
Thanks for your inputs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我读了很多教程,每个人的做法都不一样。官方 Android 文档使用 Camera 类(分步教程在链接页面上)。
我发现 这个其他教程(它使用
MediaStore
类,就像你一样),但在 Intent 上为输出文件添加了一个额外的内容。您可能需要查看这两个教程,看看其中一个是否适合您。
I read a bunch of tutorials and everyone does it different. The official Android Docs use the Camera-class (step by step tutorial on the linked page).
I found this other tutorial (which uses the
MediaStore
-class, like you), but put an extra for the Output-File on the Intent.You might want to check both of this tutorials and see if one works for you.