I'm trying to take a picture with a Google Glass App. Therefore I'm using a SurfaceView which shows the camera preview in the background. The photo is taken with an intent. The problem is that the onActivityResult method belonging to the intent is never called. I've read that this problem is a bug on Google Glass but should be closed with the newer versions of Google Glass.
onCreate Method:
private CameraSurfaceView cameraView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Initiate CameraView
cameraView = new CameraSurfaceView(this);
// Set the view
this.setContentView(cameraView);
}
Intent Calling:
@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);
}
}
This all works fine. The user sees the camera preview and when the intent is called a picture will be taken and stored. After that the user sees a prompt "Tap to Accept". After tapping the app ends but the onActivityResult method is never called.
onActivityResult Method.
@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);
}
Releasing the camera:
@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 Log for my application with Log Level "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
Thanks in advance for all answers and comments!