带有Arduino的Android SDK

时间:2015-01-18 18:55:26

标签: android arduino adk

嗨,我有这个项目代码我从初学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 个答案:

没有答案