I'm following the steps to use ADK to control mbed via the Android Studio
however their mbed adkport code (Scroll down to adkport hyperlink) requires these imports
import com.android.future.usb.UsbAccessory;
import com.android.future.usb.UsbManager;
I've noticed another thread that suggested the developer's solution was to switch it to android.hardware.usb, but when I do that, 3 different lines won't work because the hardware based package doesn't support getAccessory and getInstance symbols
Any solutions to this problem? Can't get my head around it
I tried following the steps for replacing the code to use android.hardware.usb instead but I still get an issue with their own android developer routine
//mManager = UsbManager.getInstance(context);
UsbManager mManager = (UsbManager) getSystemService(Context.USB_SERVICE);
however now it doesn't recognize getSystemService
Here's where it fails.
public void setup(Context context)
{
//mManager = UsbManager.getInstance(context);
UsbManager mManager = (UsbManager) getSystemService(Context.USB_SERVICE); //<-----
UsbAccessory[] accessoryList = mManager.getAccessoryList();
PendingIntent mPermissionIntent = PendingIntent.getBroadcast(context, 0,
new Intent(ACTION_USB_PERMISSION), 0);
IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
context.registerReceiver(mUsbReceiver, filter);
mManager.requestPermission(accessoryList[0], mPermissionIntent);
if (accessoryList[0] != null) {
mAccessory = accessoryList[0];
if(mManager.hasPermission(mAccessory))
{
openAccessory(mAccessory);
}
}
}
getSystemService()
is a method that can be called from inside anactivity
or from inside a non-activity class usingcontext
of an activity.
Since your function setup()
should be called by passing a Context
,
usbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
will solve your problem.
One of the comments (from Morrison Chang) should actually be copied as an answer (worked for me in similar situation).
His suggestion to read USB Accessory is spot on. Distilled instructions:
UsbManager.getInstance(this)
with (UsbManager) getSystemService(Context.USB_SERVICE)
.UsbManager.getAccessory(intent)
with intent.getParcelableExtra(UsbManager.EXTRA_ACCESSORY)
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With