title: How to fix permission issue with opencv in native code for android platform
body: <p>I have built opencv(with ffmpeg) for android arm64-v8a successfully, however, <code>cvCreateCameraCapture</code> returns null. <code>cvCreateFileCapture</code> works well. I found we need to set the following item for support camera:</p>
  
  <pre><code>-DWITH_V4L=1 -DHAVE_CAMV4L2=ON
  </code></pre>
  
  <p>Now, v4l have been built in opencv.
  However, when app start, native source code will open camera by opencv's function <code>cvCreateCameraCapture</code>. The following interface in cap_libv4l.cpp(opencv's source code) can not open device successfully.</p>
  
  <pre class="lang-cpp prettyprint-override"><code>static void icvInitCapture_V4L() {
      //...
      CameraNumber = 0;
      while(CameraNumber &lt; MAX_CAMERAS) {
        /* Print the CameraNumber at the end of the string with a width of one character */
        sprintf(deviceName, "/dev/video%1d", CameraNumber);
  
        /* Test using an open to see if this new device name really does exists. */
        deviceHandle = open(deviceName, O_RDONLY);
        char* strno = strerror(errno);
        LOGD("icvInitCapture_V4L wwwwwwwwwww %s !!\n", strno );
        if (deviceHandle != -1) {
          /* This device does indeed exist - add it to the total so far */
          // add indexList
          indexList|=(1 &lt;&lt; CameraNumber);
          numCameras++;
        }
        //...
      }
  </code></pre>
  
  <p>That open function failed because of permission denied.</p>
  
  <blockquote>
    <p>icvInitCapture_V4L wwwwwwwwwww Permission denied !!</p>
  </blockquote>
  
  <p>I think my android app doesn't have related permission. However, I've added the following settings in AndroidManifest.xml:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.CAMERA"/&gt;
  &lt;uses-feature android:name="android.hardware.camera" android:required="false"/&gt;
  &lt;uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/&gt;
  </code></pre>
  
  <p>And opencv functions are called in a thread in my app. My app is a service for android.</p>
  
  <p>I checked the permission about /dev/videoX as below.</p>
  
  <pre><code>1|gts4lltechn:/dev $ ls -l | grep video ls: ./event-log-tags: Permission denied
  
  crw-rw---- 1 system camera 81, 0 2017-04-01 08:37 video0
  
  crw-rw---- 1 system camera 81, 1 2017-04-01 08:37 video1
  
  crw-rw---- 1 system camera 81, 2 2017-04-01 08:37 video2
  
  crw-rw---- 1 system camera 81, 3 2017-04-01 08:37 video3
  
  crw-rw---- 1 system camera 81, 32 2017-04-01 08:37 video32
  
  crw-rw---- 1 system camera 81, 33 2017-04-01 08:37 video33
  
  crw-rw---- 1 system camera 81, 4 2017-04-01 08:37 video4
  
  crw-rw---- 1 system camera 81, 5 2017-04-01 08:37 video5
  
  crw-rw---- 1 system camera 81, 6 2018-12-20 21:28 video6
  </code></pre>
  
  <p>How to fix the permission issue for my app?</p>
  
  <p>PS: Before app start, i open the permissions for Camera and Storage by setting.</p>