我正试图用Google Glass App拍照。因此我使用SurfaceView在后台显示相机预览。这张照片是故意拍摄的。 问题是永远不会调用属于intent的onActivityResult方法。我已经读过这个问题是Google Glass上的一个错误,但应该使用较新版本的Google Glass来关闭。
onCreate方法:
private CameraSurfaceView cameraView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Initiate CameraView
cameraView = new CameraSurfaceView(this);
// Set the view
this.setContentView(cameraView);
}
意图召唤:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_camera:
take picture
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (intent != null)
{
Toast.makeText(getApplicationContext(), "Taking Picture",
Toast.LENGTH_SHORT).show();
startActivityForResult(intent, TAKE_PICTURE_REQUEST);
}
return true;
default:
return super.onOptionsItemSelected(item);
}
}
一切正常。用户看到相机预览,并且当调用意图时,将拍摄并存储图片。之后,用户会看到提示“点击接受”。点击应用程序结束后,永远不会调用onActivityResult方法。
onActivityResult方法。
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
Log.i("Camera", "Hello from onActivityResult");
// Handle photos
if (requestCode == TAKE_PICTURE_REQUEST && resultCode == RESULT_OK)
{
String picturePath = data.getStringExtra(Intents.EXTRA_PICTURE_FILE_PATH);
processPictureWhenReady(picturePath);
}
super.onActivityResult(requestCode, resultCode, data);
}
释放相机:
@Override
protected void onResume() {
super.onResume();
// Do not hold the camera during onResume
if (cameraView != null) {
cameraView.releaseCamera();
}
}
@Override
protected void onPause() {
super.onPause();
// Do not hold the camera during onPause
if (cameraView != null) {
cameraView.releaseCamera();
}
}
Logcat记录日志级别为“Info”的应用程序
05-03 08:45:02.328 29785-29785/com.dhbw.charadect I/dalvikvm-heap﹕ Grow heap (frag case) to 5.955MB for 921616-byte allocation
05-03 08:45:03.305 29785-29785/com.dhbw.charadect I/Choreographer﹕ Skipped 51 frames! The application may be doing too much work on its main thread.
05-03 08:45:03.313 29785-29785/com.dhbw.charadect W/Resources﹕ Converting to boolean: TypedValue{t=0x3/d=0x210 "res/anim/decelerate_interpolator.xml" a=1 r=0x10a0006}
05-03 08:45:04.008 29785-29785/com.dhbw.charadect I/Choreographer﹕ Skipped 30 frames! The application may be doing too much work on its main thread.
05-03 08:45:14.414 29785-29797/com.dhbw.charadect I/Camera﹕ Received CAMERA_MSG_RELEASE
提前感谢所有答案和评论!