title: Android Things camera streaming (with opencv)
body: <p>Having problem with camera permission for android things, when I try to Run the simple OpenCV application, this message is shown "It seems that you device does not support camera (or it is locked), Application will be closed. 
  <img src="https://i.stack.imgur.com/2zte0.jpg" alt="img of message">
  Logcat - filter in Android Studio showing me that OpenCV library is loaded correctly, so I think maybe the problem is permission (you can check my AndroidManifest file) or maybe bad compatibility with OpenCV library... </p>
  
  <p>Also Logcat report this error : "E/JavaCameraView: Camera #0failed to open: Fail to connect to camera service"</p>
  
  <p>Link to source code: <a href="https://github.com/mrAlex-dev/CameraPreview-AndroidThings" rel="nofollow noreferrer">https://github.com/mrAlex-dev/CameraPreview-AndroidThings</a></p>
  
  <p>P.S. I`m using: Raspberry Pi 3 B, Raspberry Pi Camera v1.3, Android Things - 0.4.1-devpreview, OpenCV-3.3.0-android-sdk... </p>
  
  <p>Can someone help me please, I`m new at this. </p>
  
  
  
  <p><strong>Code for MainActivity.java:</strong></p>
  
  <pre><code>package com.example.alexd.camerapreviewandroidthings;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.SurfaceView;
  
  import org.opencv.android.BaseLoaderCallback;
  import org.opencv.android.CameraBridgeViewBase;
  import org.opencv.android.JavaCameraView;
  import org.opencv.android.LoaderCallbackInterface;
  import org.opencv.android.OpenCVLoader;
  import org.opencv.core.CvType;
  import org.opencv.core.Mat;
  
  public class MainActivity extends Activity implements CameraBridgeViewBase.CvCameraViewListener2 {
  
      private static String TAG = "MainActivity";
      JavaCameraView javaCameraView;
      Mat mRgba;
  
      BaseLoaderCallback mLoaderCallBack = new BaseLoaderCallback(this) {
          @Override
          public void onManagerConnected(int status) {
              switch(status){
                  case BaseLoaderCallback.SUCCESS:{
                      javaCameraView.enableView();
                      break;
                  }
                  default:{
                      super.onManagerConnected(status);
                      break;
                  }
              }
              super.onManagerConnected(status);
          }
      };
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          javaCameraView = (JavaCameraView)findViewById(R.id.java_camera_view);
          javaCameraView.setVisibility(SurfaceView.VISIBLE);
          javaCameraView.setCvCameraViewListener(this);
      }
  
      @Override
      protected  void onPause(){
          super.onPause();
          if(javaCameraView!=null)
              javaCameraView.disableView();
      }
  
      @Override
      protected  void onDestroy(){
          super.onDestroy();
          if(javaCameraView!=null)
              javaCameraView.disableView();
      }
  
      @Override
      protected  void onResume(){
          super.onResume();
          if(OpenCVLoader.initDebug()){
              Log.i(TAG, "OpenCV loaded successfully");
              mLoaderCallBack.onManagerConnected(LoaderCallbackInterface.SUCCESS);
          }
          else{
              Log.i(TAG, "OpenCV not loaded");
              OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_3_0, this, mLoaderCallBack);
          }
      }
  
      @Override
      public void onCameraViewStarted(int width, int height) {
          mRgba = new Mat(height, width, CvType.CV_8UC4);
      }
  
      @Override
      public void onCameraViewStopped() {
          mRgba.release();
      }
  
      @Override
      public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
          mRgba = inputFrame.rgba();
          return mRgba;
      }
  }
  </code></pre>
  
  <p><strong>And this is AndroidManifest.xml:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.alexd.camerapreviewandroidthings"&gt;
  
      &lt;uses-permission android:name="android.permission.CAMERA" /&gt;
      &lt;uses-feature android:name="android.hardware.camera" /&gt;
      &lt;uses-feature android:name="android.hardware.camera.autofocus" /&gt;
      &lt;uses-feature android:name="android.hardware.camera2.*" /&gt;
  
      &lt;uses-permission android:name="android.permission.WRITE_SETTINGS"/&gt;
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;uses-permission android:name="com.google.android.things.permission.MANAGE_INPUT_DRIVERS" /&gt;
  
      &lt;application&gt;
          &lt;uses-library android:name="com.google.android.things" /&gt;
  
          &lt;activity android:name=".MainActivity"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.IOT_LAUNCHER" /&gt;
                  &lt;category android:name="android.intent.category.DEFAULT" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p><strong>And this is Logcat errors:</strong></p>
  
  <pre><code>09-13 08:50:29.812 1880-1880/? E/cutils-trace: Error opening trace file: No such file or directory (2)
  09-13 08:50:30.026 1880-1880/? E/memtrack: Couldn't load memtrack module (No such file or directory)
  09-13 08:50:30.026 1880-1880/? E/android.os.Debug: failed to load memtrack module: -2
  09-13 08:50:32.090 1899-1899/? E/cutils-trace: Error opening trace file: No such file or directory (2)
  09-13 08:50:32.300 1899-1899/? E/memtrack: Couldn't load memtrack module (No such file or directory)
  09-13 08:50:32.300 1899-1899/? E/android.os.Debug: failed to load memtrack module: -2
  09-13 08:50:35.356 1913-1913/? E/cutils-trace: Error opening trace file: No such file or directory (2)
  09-13 08:50:35.573 1911-1911/? E/memtrack: Couldn't load memtrack module (No such file or directory)
  09-13 08:50:35.573 1911-1911/? E/android.os.Debug: failed to load memtrack module: -2
  09-13 08:50:37.811 150-150/? E/libEGL: called unimplemented OpenGL ES API
  09-13 08:50:37.811 150-150/? E/SurfaceFlinger: glCheckFramebufferStatusOES error 0
  09-13 08:50:37.812 150-150/? E/SurfaceFlinger: got GL_FRAMEBUFFER_COMPLETE_OES error while taking screenshot
  09-13 09:00:00.843 412-429/system_process E/BatteryStatsService: no controller energy info supplied
  09-13 09:00:00.848 412-429/system_process E/KernelWakelockReader: neither /proc/wakelocks nor /d/wakeup_sources exists
  09-13 08:52:02.318 412-478/system_process E/TaskPersister: File error accessing recents directory (directory doesn't exist?).
  09-13 08:51:58.902 155-155/? E/Camera2Client: notifyError: Error condition 0 reported by HAL, requestId -1
  09-13 08:50:39.321 155-1838/? E/V4L2CameraHAL: virtual int v4l2_camera_hal::V4L2Camera::setupStreams(camera3_stream_configuration_t *):380: V4L2 only supports 1 stream configuration at a time (stream 0 is format 34, width 640, height 480, stream 1 is format 33, width 320, height 240).
  09-13 08:50:39.321 155-1838/? E/Camera: int default_camera_hal::Camera::configureStreams(camera3_stream_configuration_t *):0: Failed to setup stream set
  09-13 08:50:39.321 155-1838/? E/Camera3-Device: Camera 0: configureStreamsLocked: Set of requested inputs/outputs not supported by HAL
  09-13 08:50:39.321 155-1838/? E/Camera3-Device: Camera 0: setUpRequestLocked: Can't set up streams: Invalid argument (-22)
  09-13 08:50:39.321 155-1838/? E/Camera3-Device: Camera 0: convertMetadataListToRequestListLocked: Can't create capture request
  09-13 08:50:39.321 155-1838/? E/Camera2-StreamingProcessor: startStream: Camera 0: Unable to set preview request to start preview: Invalid argument (-22)
  09-13 08:50:39.321 155-1838/? E/Camera2Client: startPreviewL: Camera 0: Unable to start streaming preview: Invalid argument (-22)
  09-13 08:50:39.262 162-1964/? E/FileSource: Failed to open file '/system/media/audio/ui/VideoRecord.ogg'. (No such file or directory)
  09-13 08:50:39.262 162-1964/? E/GenericSource: Failed to create data source!
  09-13 08:50:39.262 155-1838/? E/MediaPlayer: error (1, -2147483648)
  09-13 08:50:39.266 162-1966/? E/FileSource: Failed to open file '/system/media/audio/ui/VideoStop.ogg'. (No such file or directory)
  09-13 08:50:39.266 162-1966/? E/GenericSource: Failed to create data source!
  </code></pre>