When you create your first Android USB Accessory with the Android ADK, one of the first things you’ll need to do is identify your accessory when you connect it to your Android device. Within the Arduino sketch for your accessory, you identify your accessory in the AndroidAccessory object.
AndroidAccessory(const char *manufacturer,
const char *model,
const char *description,
const char *version,
const char *uri,
const char *serial);
For example, the DemoKit app that comes with the ADK identifies itself as version 1.0 of the Google DemoKit accessory:
AndroidAccessory acc("Google, Inc.",
"DemoKit",
"DemoKit Arduino Board",
"1.0",
"http://www.android.com",
"0000000012345678");
You’re own app might looks something like this:
AndroidAccessory acc("My App Company",
"CoolAccessory",
"CoolAccessory Arduino Board",
"1.0",
"http://www.example.com/CoolAccessory",
"0000000012345678");
The three key one’s you’ll need to remember are manufacturer, model and version as you’ll need to define these in you’re Android app so that the device can notify your app when your accessory is connected.
When you create your Android app, there’s a few steps you need to take. First, not every Android-powered device supports the USB accessory APIs. In fact, the Android Open Accessory ADK is only supported by Android OS 3.1 and 2.3.4 platforms. To identify that your app has USB features, you need to include a element in your manifest to declare that your application uses the android.hardware.usb.accessory feature.
Next, if you’re using the add-on library, add a element with com.android.future.usb.accessory for the USB accessory library.
and set the minimum SDK of the application to API Level 10. If you’re using theandroid.hardware.usb package then the isn’t necessary and you only need to set the minimum SDK to 12 .
Lastly, you’ll want your application to be notified when your accessory is attached. Specify an and element pair for the android.hardware.usb.action.USB_ACCESSORY_ATTACHED intent in your main activity. Overall your manifest should look something like this:
...
...
android:resource="@xml/accessory_filter" />
The element references an XML resource file that includes the manufacturer, model and version you defined earlier in your Arduino sketch. Create an accessory_filter.xml resource file in the res/xml/ directory with a element to identify your accessory.
Now, when you connect your accessory to the device android will send an intent to open an appropriate application. The best part is that more than one application can respond to a given intent so multiple apps could optionally respond for the same accessory.
Generated by BlogIt
BlogIt - Auto Blogging Software for YOU!


No comments:
Post a Comment