I am working on an app and I am trying to find a way to wake the screen when I plug a usb camera to the phone while screen off on a android phone. I tried to monitor my usb connection but it didn't work, once the screen off, my app can no longer tell if a usb camera is connected. Can somebody give me some ideas about how to do that? Thanks!
Asked
Active
Viewed 117 times
1 Answers
0
First: U need start the app when usb camera inserted
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"/>
</intent-filter>
<meta-data
android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="@xml/device_filter"/>
</activity>
Second: keep screen on
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
That work for me!

Jamebes
- 96
- 8