2

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!

la-ga
  • 160
  • 2
  • 13
  • How can you be sure that onActivityResult is never called? Maybe you could add a Log in this method and post the logcat trace. – Simon Marquis May 02 '15 at 10:50
  • @SimonMarquis thank you for your comment. I added a Logcat Log to my question. Please see it above. – la-ga May 03 '15 at 06:49
  • 1
    Make sure to remove any filter from your IDE log viewer. By the way, are you correctly releasing the Camera object before launching the Intent ? (in onPause for instance) – Simon Marquis May 03 '15 at 09:16
  • @SimonMarquis I added the program code of the onPause method to release the camera object in the same class as the onActivityResult method. Please see it above. I had a look in the full log. But I'm afraid it will be too long to post it completely here. Here are two maybe interesting lines: `05-03 11:35:42.065 858-1073/? I/CameraClientV1[41b7e250]﹕ Received final jpeg from camera. [time=9236ms]` `05-03 11:35:42.143 858-858/? I/ApiTakePictureActivity[41b17740]﹕ Picture was saved, you should see your FileObserver callback now.` – la-ga May 03 '15 at 09:45
  • The `case R.id.action_camera:` switch case refers to the "Tap to accept" option? I assume that "Hello from onActivityResult" shows in your LogCat. – Koh May 12 '15 at 23:50

0 Answers0