USB Permission Popup... Every time. (Serial component)

So I can't believe it, but I actually got this working, mainly following @Anke's instructions.

  1. From App Inventor, build app to apk and save to computer.
    [Build/App (Save .apk to my computer)]

  2. From App Inventor, export keystore. [My Projects/Export Keystore]

  3. Rename android.keystore to android.ks, per this post.

  4. Download and install APK Editor Studio. You will also need to download Java JDK from Oracle. APK Editor Studio will indicate if you don't have it.

  5. Open the apk in APK Editor Studio.

  6. Click the gear icon [Preferences], click Signing APK, click Open Key Manager, enable custom keystore, navigate to your android.ks file. keystore password is "android", key alias is "androidkey", and key password is "android". Click okay. Exit preferences. (this is detailed with Anke's youtube video).

  7. Click Open Contents.

  8. Plug your arduino (or other device) into your computer usb port. Navigate to your system report (mac) or device manager, find the usb device, and find the vendor id and product id in the details. These will be hex numbers.

  9. Convert the hex vendor and product ids to decimal.

  10. From this stack exchange post, download the permission example project (zip file).

  11. Unzip the test project. Per the stack post, add the usb_device_filter.xml file in res/xml/ into the res/xml folder in your project. Edit that document with the vedor id and product id of your arduino or device. The entire code of the usb_device_filter.xml file is as follows (vendor id 9025 and product id 1 correspond to the vendor id of 0x2341 and the product id of 0x0001 of my arduino uno):

<?xml version="1.0" encoding="utf-8"?>

<resources>
	<usb-device vendor-id="9025" product-id="1" />
</resources>
  1. Open the Your AndroidManifest.xml file in your project in a code editor, and add the following to the <activity> section of your manifest, below any other intents:
<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" />  
  1. Save your APK in APK Editor Studio. Upload to your phone and install. Now the phone will ask you once when you plug in your arduino which application to use, and remember your choice. It will also auto-open the application when you plug in the device.
1 Like