Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically exit from Android Accessory Mode

I've a system with an Android Tablet + an embedded board implementing AOA Protocol.

All works fine, embedded board when connected to Android device send ACCESSORY_START command and Android enters in AOA mode. Then normal flow between two works fine too.

Now I've a question:

There is a way from embedded target to disable AOA mode without physically remove USB cable ?
A sort of ACCESSORY_STOP, so my Android target regain usual PID:VID instead of PID:VID for AOA mode ?

Or there is a way to do that programmatically with Android code ?

like image 252
Silverio Diquigiovanni Avatar asked Jul 05 '26 03:07

Silverio Diquigiovanni


1 Answers

If you want to close the accessory on app exit (without unplugging it), call System.exit(0) in Activity onDestroy(). This kills all app threads, including the accessory read thread which blocks the input stream. The accessory can then be reopened without re-plugging.

This is a partial answer to your question (just to make it clear for the watchful pedants diligently monitoring other people's business). But it's useful, because at least you can exit your app and then reconnect the accessory again without unplugging.

And yes, the problem is still with us in 2017., although it was documented ages ago.

like image 153
dslamnig Avatar answered Jul 11 '26 11:07

dslamnig



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!