I am working on a project about android and I am trying to set a connection between device and ADK my problem is .getAccessory(); method. It should be taken from UsbManager class, but eclipse throws following error:

The method getAccessory(Intent) is undefined for the type UsbManager

And my code sample is here:

private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver(){

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        String action = intent.getAction();
        if(ACTION_USB_PERMISSION.equals(action)){
            synchronized (this) {
                UsbAccessory accessory = UsbManager.getAccesory(intent);
                if(intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)){
                    openAccessory(accessory);//q
                }
            }
        }

        else if (UsbManager.ACTION_USB_ACCESSORY_DETACHED.equals(action)){
            UsbAccessory accessory = UsbManager.getAccessory(intent);
            if(accessory != null && accessory.equals(mAccesory)){
                closeAccessory();//q
            }
        }
    }

};

Do you have any idea what to do?

Maybe I am wrong, in this case what can I use for its task?

Edit: JVM cannot see the getInstance() method too which I used in OnCreate(Bundle savedInstanceState).

有帮助吗?

解决方案

I have just done my project build target 4.0.3 to Google APIs(API lvl 17) and it was solved

其他提示

You have to use UsbManager and UsbAccessory from these imports:

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

not from

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

in order to have UsbManager.getAccessory(intent);

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top