Comments (4)
Hi,
If you want to use two camera at the same time on this sample, it is better to give permanent permission to app for each camera at least before starting second camera. Because, as you can see sample project, if the activity lost focus (ex. by displaying permission request dialog of USB), app try to stop/release all camera and unregister/release USBMonitor on onPause/onDestroy method.
It is possible to keep camera and USBMonitor working while background but just removing those code is not a good idea and it needs additional code.
I assume at least following modification will need.
- pass Application context instead of Activity when creating USBMonitor on
onCreate
- check whether mUSBMonitor is null or not when creation.
- register USBMonitor after creating instead of
onResume
. - unregister USBMonitor on
onDestroy
instead ofonPause
. - add intent filter for USB attaching event so that app can keep permission permanently.
- check whether Activity is active or not on all code related to USBMonitor and View and their life cycle(Note:all View and Activity context will become invalid if the Activity lost focus).
...
This is just sample and the main target is showing each concept by easy way/simple code. Those modifications will make app complex and difficult to understand what it do.
saki
from uvccamera.
Hi,
I don't mind if the preview is destroyed if the application looses focus.
How can I keep the permission permanently as you write?
And sorry, you are right. This is not an issue of the library but of the sample project, but I just can't figure out a way how to get it to work. I worked on this for quite a while.
Thanks for your help!
On Oct 14, 2015 9:55 PM, saki [email protected] wrote:Hi,
If you want to use two camera at the same time on this sample, it is better to give permanent permission to app for each camera at least before starting second camera. Because, as you can see sample project, if the activity lost focus (ex. by displaying permission request dialog of USB), app try to stop/release all camera and unregister/release USBMonitor on onPause/onDestroy method.
It is possible to keep camera and USBMonitor working while background but just removing those code is not a good idea and it needs additional code.
I assume at least following modification will need.
- pass Application context instead of Activity when creating USBMonitor on onCreate
- check whether mUSBMonitor is null or not when creation.
- register USBMonitor after creating instead of onResume.
- unregister USBMonitor on onDestroy instead of onPause.
- add intent filter for USB attaching event so that app can keep permission permanently.
- check whether Activity is active or not on all code related to USBMonitor and View and their life cycle(Note:all View and Activity context will become invalid if the Activity lost focus).
...
This is just sample and the main target is showing each concept by easy way/simple code. Those modifications will make app complex and difficult to understand what it do.
saki
—Reply to this email directly or view it on GitHub.
from uvccamera.
Hi,
To Holding a permanent permission for USB, you need to add intent filter to activity
section onAndroidManifest.xml
. Additionally, it is better to add launchMode
in activity
section as singleTask
orsingleInstance
(I usually use singleTask
).
(Regarding details about launchMode
and why it is better to set as this, please check Android Developer site.)
<activity
android:launchMode="singleTask"
...
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
<meta-data
android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="@xml/device_filter" />
</intent-filter>
...
You can see this on AndroidManifest.xml
of UsbCameraTest4 sample project.
If there is above intent filter in AndroidManifest.xml
and once user choose the app as default app(always use the app for the device), Android system automatically give a permission to the Activity every time connecting the USB device (and you can not select other similar app). You can clear this setting on Apps
setting.
You can also add USB_DEVICE_DETACHED
intent filter to your AndroidManifest.xml
, but some Android devices with some Android version can not handle this intent filter correctly.
Please mind that adding above intent filter let app accept all connecting event of UVC camera. This means when connect UVC camera to your device and the app does not have permission for the device, Android system always ask you permission. If you only need specific UVC camera, please add the vendor id and product id to device_filter.xml
saki
from uvccamera.
Thanks for your help. Now, when I plug in the hub the app opens and the preview for both cameras starts fine, just as I wanted!
from uvccamera.
Related Issues (20)
- A patch for USBMonitor.java to avoid crash in USB 3.0 HUB
- Working with FLIR Boson camera
- jpeg_read_scanlines crash
- java.lang.RuntimeException: Unable to start activity ComponentInfo : java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity HOT 1
- How to make zoom of texture ( input frames of camera) in UVCCameraTextureView ? HOT 1
- After multiple attempts to open the UVC camera, it fails to reopen. Assistance is requested HOT 2
- Caused by: org.gradle.internal.resolve.ModuleVersionNotFoundException: Could not find com.serenegiant:common:2.12.5.
- The preview freezes when you press record on the Samsung a54 HOT 1
- MediaRecorder instead of MediaEncoder
- [Security] libjpeg-turbo used in this project is vulnerable
- Can't get started HOT 1
- Android11, RK3568, null pointer dereference HOT 2
- Permission pop-up giving illegal agruement exception in TargetSdk>27
- SQ 29 Camera does not display image HOT 1
- 有人知道如何解决4K以上画质得延迟问题吗?解决成功可以给予报酬。 HOT 1
- Android app crashing when using multiple .aar libraries
- Difference between ( 'Y', '8', ' ', ' ' ) and ('Y', '8', '0', '0') HOT 1
- Execution failed for task ':libuvc:ndkBuild'. HOT 2
- Preview last frame when external camera is removed. HOT 2
- usbCameraTest3 does not work when using the Surface Encoder
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from uvccamera.