Events:
1.USB device plugged in.
- Prompt appears saying: "Open appName when this USB device is connected?"
- Press cancel -> app stays open | press okay -> app restarts
Required behaviour: The app either does not show the dialog and automatically opens the app when it's not in the foreground, or, when the app is in the foreground then when the user presses okay the app does not restart.
Attempted solution: I've tried making sure every Activity's launch mode is set to "SingleTask"
. This solution worked here but when I did the same thing the app still restarted.
Question in a nutshell: How do I stop my app restarting when the user says to open the app when the device is connected? Or, how do I stop this prompt entirely whilst still enabling my app to start when this USB device is connected?
I've seen similar questions which deal with stopping a prompt showing which asks whether the app should be allowed to access the connected device, but, my issue is dealing with a different prompt.
Thanks in advance.
the app uses an
IntentFilter
with anAppChooser
orLauncher
dialog https://developer.android.com/guide/components/intents-filters.htmlthis always happens when you use an
IntentFilter
onandroid.hardware.usb.action.USB_DEVICE_ATTACHED
. Another possibility is that the dialog is an AppChooser or launcher dialog that is invoked when there are multiple apps (or multiple instances of the same / your app) that capture the USB attach event . This is why when you pressCancel
the app stays open.https://developer.android.com/guide/topics/connectivity/usb/host.html
this is a systems dialog that is internally linked to the
android.hardware.usb.action.USB_DEVICE_ATTACHED
event so disabling it will be difficult. there is the possibility to use<activity-alias>
, https://developer.android.com/guide/topics/manifest/activity-alias-element.html you can route intents with it:http://www.stackoverflow.com/questions/40182096/usb-permissions-without-prompt/40182413#40182413
http://blog.danlew.net/2014/01/16/preserve-your-launchers-use-activity-alias/ (Is there any way to have one and only one instance of each activity?)