4

I want to access extern usb cameras via v4l on android.

I tried SimpleWebCam. After some slight modifications of the original source codes, i achieved to make it work on a rooted android device. However, on unrooted devices, it keeps complaining about "not have permission to access "/dev/video*". I checked the permission of /dev/video* with "ls -l /dev/video*", and got

crw-rw---- system camera 81, 0 2015-08-18 18:31 video0

I understand that it means /dev/video* are owned by system, and are readable/writable to users in group "camera". So I think if i add

<uses-permission android:name="android.permission.CAMERA" />

in the manifest of my app, the user id of my app will be added to the group "camera", then my app will be allowed to read data from /dev/video*.

But, it still complains about "not have permission to access /dev/video*" now.

i also tried

<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />

, but still not working.

Do i miss somthing or misunderstand somthing. Any help or discussion will be appreciated.

The codes i used to open device are

int opendevice(int i)
{
struct stat st;

sprintf(dev_name,"/dev/video%d",i);

if (-1 == stat (dev_name, &st)) {
    LOGE("Cannot identify '%s': %d, %s", dev_name, errno, strerror (errno));
    return ERROR_LOCAL;
}

if (!S_ISCHR (st.st_mode)) {
    LOGE("%s is no device", dev_name);
    return ERROR_LOCAL;
}

fd = open (dev_name, O_RDWR);// | O_NONBLOCK, 0);

if (-1 == fd) {
    LOGE("Cannot open '%s': %d, %s", dev_name, errno, strerror (errno));
    return ERROR_LOCAL;
}
return SUCCESS_LOCAL;
}

The return value of open is always -1, with logcat:

 Cannot open '/dev/video3': 13, Permission denied
Yang Kui
  • 548
  • 5
  • 11

2 Answers2

2

I finally achieve to read images from the external usb camera on unrooted android devices using an opensource project named uvccamera. Here is the link, https://github.com/saki4510t/UVCCamera

Yang Kui
  • 548
  • 5
  • 11
0

Try to add also

<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />

in your manifest file:

http://developer.android.com/reference/android/hardware/Camera.html

bendaf
  • 2,981
  • 5
  • 27
  • 62
  • Thanks for the quick reply, i am now off work and will try it tomorrow. – Yang Kui Aug 19 '15 at 12:51
  • could you post your whole stacktrace? – bendaf Aug 21 '15 at 13:43
  • the stacktrace may not help in this case. instead, i paste the codes i used and the corresponding logcat here. hope it helps. – Yang Kui Aug 22 '15 at 02:17
  • well, that's pretty interesting, if I were you I would add all of the permissions to the manifest file, just to try if there is a permission for this :/. Here is the list for all of them: http://developer.android.com/reference/android/Manifest.permission.html – bendaf Aug 22 '15 at 07:46