# APDE USB / OTG communication

**URL:** <https://discourse.processing.org/t/apde-usb-otg-communication/30114>\
**Category:** Processing for Android\
**Created:** [May 16, 2021, 12:13am UTC](https://discourse.processing.org/t/apde-usb-otg-communication/30114 "2021-05-16T00:13:07Z")\
**Posts on this page:** 1\
**Showing post:** 24

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [May 17, 2021, 11:15am UTC](https://discourse.processing.org/t/apde-usb-otg-communication/30114/24 "2021-05-17T11:15:28Z")

</div>

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

> [@ZENAR57](#):
>
> Impossible to grant access to USB port through AndroidManifest · Issue #84 · Calsign/APDE · GitHub

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](https://github.com/Calsign/APDE/issues/84)_

_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.](https://github.com/Calsign/APDE)

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**
>
> ```auto
> <?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](https://github.com/inventit/processing-android-serial/blob/master/src/main/examples/PulseSensor11574/res/xml/device_filter.xml)_

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:

> **[GitHub - inventit/processing-android-serial: Android Serial Library for...](https://github.com/inventit/processing-android-serial)**
>
> Android Serial Library for Processing. Contribute to inventit/processing-android-serial development by creating an account on GitHub.

`:)`

---

_[View the full topic](https://discourse.processing.org/t/apde-usb-otg-communication/30114)._
