arduino on android 4.0

demokit (adk_release_20120606.zip (https://dl-ssl.google.com/android/adk/adk_release_20120606.zip )) 在我的zte u970上跑不起来。一直以为是厂家把ADK部分删除了。仔细阅读了文档( http://developer.android.com/guide/topics/connectivity/usb/accessory.html )后发现,是我搞错了。


Android 2.3.4,应当使用名字空间com.android.future.usb,这里是作为android的add-on

在Android3.1以后,应当使用名字空间android.hardware.usb:这里是作为android 框架的一部分。


代码也要做相应修改


ADK两个版本的比较
add-on library(android 2.3.4)platform(android 3.1)
UsbManager manager = UsbManager.getInstance(this);
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
UsbAccessory accessory = UsbManager.getAccessory(intent);
UsbAccessory accessory = (UsbAccessory) intent.getParcelableExtra(UsbManager.EXTRA_ACCESSORY);

Set the minimum SDK of the application to API Level 10Set the minimum SDK of the application to API Level 12
add the <uses-library> element specifyingcom.android.future.usb.accessory include a<uses-feature> element that declares that your application uses theandroid.hardware.usb.accessory feature.

常用代码

Android App USB Code

In the ADK 2012 Android app, the code for handling USB connections is encapsulated in a UsbConnection class. This class sets up a BroadcastReceiver to listen for USB events and then attempts to connect when a matching connection event is received. Here is a summary of the relevant code:

import com.android.future.usb.UsbAccessory;
import com.android.future.usb.UsbManager;

mUSBManager = UsbManager.getInstance(this);
UsbAccessory acc = mUSBManager.getAccessoryList()[0];

if (!mUSBManager.hasPermission(acc)) return;

The ADK 2012 app uses the support library to implement the USB accessory connections, in order to support devices running Android 2.3.4 (API Level 10). If you only need to support Android 3.1 (API Level 12) and higher devices, you can replace the first 4 lines the following code:

import android.hardware.usb.UsbAccessory
import android.hardware.usb.UsbManager

mUSBManager = (UsbManager) getSystemService(Context.USB_SERVICE);
UsbAccessory acc = (UsbAccessory)
                   intent.getParcelableExtra(UsbManager.EXTRA_ACCESSORY);

Note that the app only receives events when the USB accessory identification information matches the information in theres/xml/usb_accessory_filter.xml file, referenced by the application’s manifest statement:

<meta-data
    android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
    android:resource="@xml/usb_accessory_filter" />

Connections from other USB devices are not received by the ADK 2012 accessory.




ref:

adk_release_20120606.zip (https://dl-ssl.google.com/android/adk/adk_release_20120606.zip )

http://developer.android.com/guide/topics/connectivity/usb/accessory.html

http://developer.android.com/tools/adk/adk2.html

http://developer.android.com/tools/adk/adk.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值