Android App Won't Remember USB Permission
android, java
Solution
We ended up opening the app automatically when the USB is inserted into the phone, because our project deals with the app being open all day.
The app only asks for permission to use the USB once for the phone and remembers it now, as long as the user connects the USB before opening the app and the phone is unlocked. The phone even remembers the permission after the phone is restarted.
This is kind of a work around, but it works for our needs. Hopefully this will help some others with the same problem.
Problem
I am trying to stop the app I am working on from asking for USB permissions each time the USB device is disconnected. I have followed: USB device access pop-up suppression? without much luck. The app does remember the USB device until the device is unplugged. If it matters I am trying to connect the app to an Arduino Teensy. This is what my manifest activity looks like ``` <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <intent-filter> <!-- For receiving data from another application --> <action android:name="android.intent.action.SEND" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="text/plain" /> </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/usb_device_filter" /> </activity> </application> ``` And here is my usb_device_filter file: ``` <?xml version="1.0" encoding="utf-8"?> <resources> <usb-device vendor-id="--hidden--" product-id="--hidden--" /> </resources> ``` Any help is welcome. EDIT: I also look over at the Android Developer page and they say when using an intent filter for USB connections: If users accept, your application automatically has permission to access the device until the device is disconnected. I would also like to point out that the suggested duplicate does not have the same issue as I am trying to solve. Their problem is having two activities while my problem deals with just one. https://developer.android.com/guide/topics/connectivity/usb/host