Android ADK с Arduin

Привет, у меня есть этот код проекта, я получил его из Android ADK с книгой Arduino, но он не работает из-за импорта UsbAccessory; UsbManager;
.........................................................

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

public void onCreate (Bundle savedInstanceState) {
        super.onCreate (savedInstanceState);

        mUsbManager = UsbManager.getInstance(this);
        mPermissionIntent = PendingIntent.getBroadcast (this, 0, new Intent (
                ACTION_USB_PERMISSION), 0);
        IntentFilter filter = new IntentFilter (ACTION_USB_PERMISSION);
        filter.addAction (UsbManager.ACTION_USB_ACCESSORY_DETACHED);
        registerReceiver (mUsbReceiver, filter);

        setContentView (R.layout.activity_main);
        textView = (TextView) findViewById (R.id.textView);
    }
...........
    private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver () {
            @Override
            public void onReceive (Context context, Intent intent) {
                String action = intent.getAction ();
                if (ACTION_USB_PERMISSION.equals (action)) {
                    synchronized (this) {
                        UsbAccessory accessory = UsbManager.getAccessory (intent);
                        if (intent.getBooleanExtra (
                                UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
                            openAccessory (accessory);
                        } else {
                            Log.d (TAG, "permission denied for accessory "
                                    + accessory);
                        }
                        mPermissionRequestPending = false;
                    }
                } else if (UsbManager.ACTION_USB_ACCESSORY_DETACHED.equals (action)) {
                    UsbAccessory accessory = UsbManager.getAccessory (intent);
                    if (accessory != null && accessory.equals (mAccessory)) {
                        closeAccessory ();
                    }
                }
            }
        };

0 ответов

Другие вопросы по тегам