APDE USB / OTG communication

A working solution, with a bit of work from you, is already in your post:

This was my starting point and I have shared this link with you before:
Impossible to grant access to USB port through AndroidManifest · Issue #84 · Calsign/APDE · GitHub

Calsign states:

Yes technically you can achieve what you want by modifying the manifest template, but this isn’t really a solution for most users because it means that every sketch built with the modified version of APDE will have the uses-feature tag.

@glv steps to modify the manifest template:

  1. Download the APDE.apk (APDE v0.5.1 Alpha) from:
    GitHub - Calsign/APDE: Source code for APDE: Create and run Processing sketches on an Android device.

  2. Use an APK Editor of your choice (I used APK Easy Tools on my PC) and modify this file:
    \assets\templates\AppManifest.xml.tmpl

To this:

Modified AppManifest.xml.tmpl
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package=""
          android:versionCode="1"
          android:versionName="1.0"> 

    <!-- Added -->
    <uses-feature android:name="android.hardware.usb.host"/>
					
    <uses-sdk android:minSdkVersion="@@min_sdk@@" android:targetSdkVersion="@@target_sdk@@" />
    <application android:label=""
                 android:icon="@drawable/icon">
        <activity android:name=".MainActivity"
                  android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
						
            <!-- Added -->
            <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> 
    </application>
</manifest>
  1. Install the modified APDE.APK on the Android phone.

  2. Add this directory and file /res/xml/device_filter.xml to the sketch folder.
    This device_filter.xml (there are others) worked for me:
    processing-android-serial/src/main/examples/PulseSensor11574/res/xml/device_filter.xml at master · inventit/processing-android-serial · GitHub

  3. APDE Preview mode did not work (some more modifications would be necessary) however I created an App and this worked.

This works for my needs.

I have tested it and able to reproduce the results. :)

I wrote a very simple sketch on the Arduino to count and send to serial port and received this with my app (used the modified APDE to make this) on the Android phone.

I now have serial communication between my Android Phone (Version 9) and Arduino Mega 2560 R3 (using an OTG cable) with an app created with the modified APDE.

I have not worked with the APDE or an APK editor before so this was a worthwhile adventure and I now have some new tools, experience and skills for my technical resume.

Be methodical, meticulous and document while working on this.

The rest is up to you. Enjoy the journey!

UPDATE 2021-05-21
I used the AndroidSerial for Processing library latest release 0.2.0 available here:

:)

3 Likes