On Jun 7, 2012, at 2:00 AM, theshadow124 wrote:
> I have created an app to display the data from the device, but I really dont 
> know where to start for the USB stuff. It all seams to have very little 
> documentation and no examples for use with M4A.

We haven't had a chance to port the USB samples, so you'll need to rely on the 
Java samples and port as needed:

        http://developer.android.com/resources/samples/USB/index.html

> I am stuck trying to get the accessory list... I have:
> 
>                dynamic t = GetAccessoryList();
> But this gives error: The name 'GetAccessoryList' does not exist in the 
> current context

GetAccessoryList()[0] is an instance method on UsbManager, and unless you're a 
UsbManager subclass, you'll need to provide an instance:

        dynamic t = manager.GetAccessoryList();

Furthermore, dynamic has some hefty runtime requirements, so it should be 
avoided unless you _really_ need it:

        UsbAccessory[] t = manager.GetAccessoryList()?

Where do we get `manager` from? The Java UsbManager documentation [1, 2] states 
how to obtain an instance:

        UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);

Alas, that's Java, so port to C#:

        UsbManager manager = (UsbManager) GetSystemService (Context.UsbService);

GetSystemService() is an Android.Content.Context instance method. Calling it 
requires that you have a Context instance. Activity subclasses Context, so if 
you're subclassing Activity (as is frequently the case), you can call 
GetSystemService() without an instance variable. If you move this to another 
class, you'll also need to provide the Context instance:

        public static UsbAccessory[] GetUsbAccessories (Context context)
        {
                UsbManager manager = (UsbManager) context.GetSystemService 
(Context.UsbService);
                return manager.GetAccessoryList ();
        }

Then within your Activity:

        UsbAccessory[] t = GetUsbAccessories (this);

 - Jon

[0] 
http://androidapi.xamarin.com/?link=M%3aAndroid.Hardware.Usb.UsbManager.GetAccessoryList

[1] http://developer.android.com/reference/android/hardware/usb/UsbManager.html

[2] Unfortunately our documentation import didn't import this code fragment. :-(

Our documentation does contain [Android Documentation] links which will open up 
the corresponding Java documentation.

_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to