@Override
  public void onResume() {
    super.onResume();
    startBackgroundThread();

    // When the screen is turned off and turned back on, the SurfaceTexture is already
    // available, and "onSurfaceTextureAvailable" will not be called. In that case, we can open
    // a camera and start preview from here (otherwise, we wait until the surface is ready in
    // the SurfaceTextureListener).
    if (mTextureView.isAvailable()) {
      openCamera(mCameraId, mTextureView.getWidth(), mTextureView.getHeight());
    } else {
      mTextureView.setSurfaceTextureListener(mSurfaceTextureListener);
    }
  }
  @Override
  protected void onResume() {
    super.onResume();
    startBackgroundThread();
    startSpeechRecognizer();

    // When the screen is turned off and turned back on, the SurfaceTexture is already
    // available, and "onSurfaceTextureAvailable" will not be called. In that case, we can open
    // a camera and start preview from here (otherwise, we wait until the surface is ready in
    // the SurfaceTextureListener).
    if (mTextureView.isAvailable()) {
      lawg.d("Has camera permission? " + hasPermission(Manifest.permission.CAMERA));
      if (hasPermission(Manifest.permission.CAMERA)) {
        startCamera2(mTextureView.getWidth(), mTextureView.getHeight());
      } else {
        ActivityCompat.requestPermissions(
            CameraActivity.this,
            new String[] {Manifest.permission.CAMERA},
            CAMERA_PERMISSIONS_REQUEST);
      }
    } else {
      mTextureView.setSurfaceTextureListener(mSurfaceTextureListener);
    }
  }