當前位置: 首頁>>代碼示例>>Java>>正文


Java UsbManager類代碼示例

本文整理匯總了Java中android.hardware.usb.UsbManager的典型用法代碼示例。如果您正苦於以下問題:Java UsbManager類的具體用法?Java UsbManager怎麽用?Java UsbManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


UsbManager類屬於android.hardware.usb包,在下文中一共展示了UsbManager類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: enumerate

import android.hardware.usb.UsbManager; //導入依賴的package包/類
public static UsbHidDevice[] enumerate(Context context, int vid, int pid) throws Exception {
    UsbManager usbManager = (UsbManager) context.getApplicationContext().getSystemService(Context.USB_SERVICE);
    if (usbManager == null) {
        throw new Exception("no usb service");
    }

    Map<String, UsbDevice> devices = usbManager.getDeviceList();
    List<UsbHidDevice> usbHidDevices = new ArrayList<>();
    for (UsbDevice device : devices.values()) {
        if ((vid == 0 || device.getVendorId() == vid) && (pid == 0 || device.getProductId() == pid)) {
            for (int i = 0; i < device.getInterfaceCount(); i++) {
                UsbInterface usbInterface = device.getInterface(i);
                if (usbInterface.getInterfaceClass() == INTERFACE_CLASS_HID) {
                    UsbHidDevice hidDevice = new UsbHidDevice(device, usbInterface, usbManager);
                    usbHidDevices.add(hidDevice);
                }
            }
        }
    }
    return usbHidDevices.toArray(new UsbHidDevice[usbHidDevices.size()]);
}
 
開發者ID:benlypan,項目名稱:UsbHid,代碼行數:22,代碼來源:UsbHidDevice.java

示例2: onCreate

import android.hardware.usb.UsbManager; //導入依賴的package包/類
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent intent = getIntent();
    if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(intent.getAction())) {
        UsbDevice usbDevice = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
        Log.d(TAG, "USB DVB-T attached: " + usbDevice.getDeviceName());
        Intent newIntent = new Intent(ACTION_DVB_DEVICE_ATTACHED);
        newIntent.putExtra(UsbManager.EXTRA_DEVICE, usbDevice);
        try {
            startActivity(newIntent);
        } catch (ActivityNotFoundException e) {
            Log.d(TAG, "No activity found for DVB-T handling");
        }
    }

    finish();
}
 
開發者ID:martinmarinov,項目名稱:AndroidDvbDriver,代碼行數:20,代碼來源:UsbDelegate.java

示例3: onCreate

import android.hardware.usb.UsbManager; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mRed = new SeekText(R.id.seek_red, R.id.txt_red, 255);
    mGreen = new SeekText(R.id.seek_green, R.id.txt_green, 255);
    mBlue = new SeekText(R.id.seek_blue, R.id.txt_blue, 255);
    mImageView = (ImageView) findViewById(R.id.img_preview);
    mImageView.setBackgroundColor(Color.argb(0, 255, 255, 255));

    mUsbManager = (UsbManager) getSystemService(USB_SERVICE);
    mPermIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);

    mUsbThread = new HandlerThread("USB Handler");
    mUsbThread.start();
    mUsbHandler = new Handler(mUsbThread.getLooper());
    mMainHandler = new Handler();
}
 
開發者ID:nasa,項目名稱:astrobee_android,代碼行數:20,代碼來源:MainActivity.java

示例4: onNewIntent

import android.hardware.usb.UsbManager; //導入依賴的package包/類
@Override
protected void onNewIntent(Intent intent) {
  super.onNewIntent(intent);

  if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(intent.getAction())) {
    UsbDevice usbDevice = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
    RobotLog.vv(TAG, "ACTION_USB_DEVICE_ATTACHED: %s", usbDevice.getDeviceName());

    if (usbDevice != null) {  // paranoia
      // We might get attachment notifications before the event loop is set up, so
      // we hold on to them and pass them along only when we're good and ready.
      if (receivedUsbAttachmentNotifications != null) { // *total* paranoia
        receivedUsbAttachmentNotifications.add(usbDevice);
        passReceivedUsbAttachmentsToEventLoop();
      }
    }
  }
}
 
開發者ID:SCHS-Robotics,項目名稱:Team9261-2017-2018,代碼行數:19,代碼來源:FtcRobotControllerActivity.java

示例5: mountDevice

import android.hardware.usb.UsbManager; //導入依賴的package包/類
private FileSystem mountDevice() {
    Log.d("MountTask", "opening OTG disk...");
    manager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
    HashMap<String, UsbDevice> devices = manager.getDeviceList();
    Iterator<UsbDevice> deviceIterator = devices.values().iterator();
    if (devices.size() < 1) {
        Log.e("MountTask", "No device found...");
        errorMessageId = R.string.pluginDisk;
    } else if (deviceIterator.hasNext()) {
        device = deviceIterator.next();
        Log.d("MountTask", String.format("Found device: %04X:%04X, Class: %02X:%02X, at %s",
                device.getVendorId(), device.getProductId(),
                device.getDeviceClass(), device.getDeviceSubclass(),
                device.getDeviceName()));
        if (manager.hasPermission(device)) {
            return claimInterface(device);
        } else {
            Log.e("MountTask", "No permission granted to access this device, requesting...");
            manager.requestPermission(device,
                    PendingIntent.getBroadcast(context, 0, new Intent(MainActivity.ACTION_USB_PERMISSION), 0));
        }
        Log.d("MountTask", "No more devices found");
    }
    return null;
}
 
開發者ID:rostskadat,項目名稱:OTGDiskBackup,代碼行數:26,代碼來源:MountTask.java

示例6: onReceive

import android.hardware.usb.UsbManager; //導入依賴的package包/類
public void onReceive(Context context, Intent intent) {
if (ACTION_USB_PERMISSION.equals(intent.getAction())) {
    synchronized (this) {
        final UsbDevice device = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
        if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
            if (device != null) {
                currentDevice = device;
                Log.i(TAG, "permission granted for device: " + device);
                // Try again to open device, now we have permission
                final int connectUsbDeviceStatus = openDevice(device);
                processConnectUsbDeviceStatus(connectUsbDeviceStatus);
            }
        } else {
            Log.d(TAG, "permission denied for device: " + device);
            processConnectUsbDeviceStatus(R.string.connect_usb_device_status_error_permission_denied);
        }
    }
}
}
 
開發者ID:videgro,項目名稱:Ships,代碼行數:20,代碼來源:OpenDeviceActivity.java

示例7: onCreate

import android.hardware.usb.UsbManager; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (!MainActivity.isNativeLibraryLoaded()) {
        final String msg=getString(R.string.connect_usb_device_status_error_native_library_not_loaded);
        Analytics.getInstance().logEvent(Analytics.CATEGORY_ANDROID_DEVICE,msg, "");
        finish(ERROR_REASON_NATIVE_LIBRARY_NOT_LOADED,msg);
        return;
    }

    setContentView(R.layout.progress);

    usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
    permissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);

    registerReceiver(usbReceiver,new IntentFilter(ACTION_USB_PERMISSION));

    Log.d(TAG, "onCreate");
}
 
開發者ID:videgro,項目名稱:Ships,代碼行數:21,代碼來源:OpenDeviceActivity.java

示例8: onReceive

import android.hardware.usb.UsbManager; //導入依賴的package包/類
public void onReceive(Context context, Intent intent) {
    final String action = intent.getAction();

    if (action != null) {

        switch (action) {
            case UsbManager.ACTION_USB_DEVICE_DETACHED:
                final UsbDevice detDevice = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
                final String detMsg="Device DEtached";
                Log.v(TAG,detMsg+" "+detDevice);
                Analytics.getInstance().logEvent(Analytics.CATEGORY_RTLSDR_DEVICE,detMsg,detDevice.toString());
                break;
            case UsbManager.ACTION_USB_DEVICE_ATTACHED:
            case UsbManager.ACTION_USB_ACCESSORY_ATTACHED:
                final UsbDevice attDevice = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
                final String attMsg="Device atached";
                Log.v(TAG,attMsg+" "+attDevice);
                Analytics.getInstance().logEvent(Analytics.CATEGORY_RTLSDR_DEVICE,attMsg,attDevice.toString());
                deviceAttached();
            break;
            default:
                // Nothing to do
                break;
        } // END SWITCH
    }
}
 
開發者ID:videgro,項目名稱:Ships,代碼行數:27,代碼來源:MainActivity.java

示例9: onCreate

import android.hardware.usb.UsbManager; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	// FIXME: Observed exception "IllegalAccessException (@MainActivity:onCreate:16) {main}"

       // Init some singletons which need the Context
       Analytics.getInstance().init(this);
       SettingsUtils.getInstance().init(this);

	setContentView(R.layout.activity_main);

	final ActionBar actionBar=getActionBar();
	if (actionBar!=null) {
           actionBar.setDisplayShowTitleEnabled(true);
           //actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
       }

       final IntentFilter filter=new IntentFilter();
       filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
       filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
       registerReceiver(usbReceiver,filter);
}
 
開發者ID:videgro,項目名稱:Ships,代碼行數:23,代碼來源:MainActivity.java

示例10: UsbHidDevice

import android.hardware.usb.UsbManager; //導入依賴的package包/類
private UsbHidDevice(UsbDevice usbDevice, UsbInterface usbInterface, UsbManager usbManager) {
    mUsbDevice = usbDevice;
    mUsbInterface = usbInterface;
    mUsbManager= usbManager;

    for (int i = 0; i < mUsbInterface.getEndpointCount(); i++) {
        UsbEndpoint endpoint = mUsbInterface.getEndpoint(i);
        int dir = endpoint.getDirection();
        int type = endpoint.getType();
        if (mInUsbEndpoint == null && dir == UsbConstants.USB_DIR_IN && type == UsbConstants.USB_ENDPOINT_XFER_INT) {
            mInUsbEndpoint = endpoint;
        }
        if (mOutUsbEndpoint == null && dir == UsbConstants.USB_DIR_OUT && type == UsbConstants.USB_ENDPOINT_XFER_INT) {
            mOutUsbEndpoint = endpoint;
        }
    }
}
 
開發者ID:benlypan,項目名稱:UsbHid,代碼行數:18,代碼來源:UsbHidDevice.java

示例11: onCreate

import android.hardware.usb.UsbManager; //導入依賴的package包/類
@Override
public void onCreate() {
    super.onCreate();

    if (DEBUG) Log.d(TAG, "onCreate");

    mUsbManager = (UsbManager) getBaseContext().getSystemService(Context.USB_SERVICE);
    mAudioManager = (AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);
    mPowerManager = (PowerManager) getBaseContext().getSystemService(Context.POWER_SERVICE);
    mInputManager = (InputManager) getBaseContext().getSystemService(Context.INPUT_SERVICE);

    ConfigStorage.SerialPortIdentifier portIdentifier =
            ConfigStorage.readDefaultPort(getBaseContext());
    if (DEBUG) Log.d(TAG, "onCreate, portIdentifier: " + portIdentifier);
    if (portIdentifier != null) {
        UsbSerialPort port = findUsbSerialPort(portIdentifier);
        if (port == null) {
            Log.w(TAG, "Unable to find usb serial port,  make sure device is connected: "
                    + portIdentifier);
            return;
        }

        onUsbSerialPortChanged(port);
    }
}
 
開發者ID:OpilkiInside,項目名稱:bimdroid,代碼行數:26,代碼來源:BmwIBusService.java

示例12: onCreate

import android.hardware.usb.UsbManager; //導入依賴的package包/類
@Override
public boolean onCreate() {
    Context context = getContext();

    updateSettings();
    usbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE);

    IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_USB_PERMISSION);
    filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
    filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
    context.registerReceiver(mUsbReceiver, filter);

    updateRoots();
    return true;
}
 
開發者ID:kranthi0987,項目名稱:easyfilemanager,代碼行數:17,代碼來源:UsbStorageProvider.java

示例13: onReceive

import android.hardware.usb.UsbManager; //導入依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    UsbDevice usbDevice = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
    String deviceName = usbDevice.getDeviceName();
    if (UsbStorageProvider.ACTION_USB_PERMISSION.equals(action)) {
        boolean permission = intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false);
        if (permission) {
            discoverDevice(usbDevice);
            notifyRootsChanged();
            notifyDocumentsChanged(getContext(), getRootId(usbDevice)+ROOT_SEPERATOR);
        } else {
            // so we don't ask for permission again
        }
    } else if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)
            || UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
        updateRoots();
    }
}
 
開發者ID:kranthi0987,項目名稱:easyfilemanager,代碼行數:20,代碼來源:UsbStorageProvider.java

示例14: onNewIntent

import android.hardware.usb.UsbManager; //導入依賴的package包/類
@Override
protected void onNewIntent(Intent intent) {
  super.onNewIntent(intent);

  if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(intent.getAction())) {
    UsbDevice usbDevice = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
    if (usbDevice != null) {  // paranoia
      // We might get attachment notifications before the event loop is set up, so
      // we hold on to them and pass them along only when we're good and ready.
      if (receivedUsbAttachmentNotifications != null) { // *total* paranoia
        receivedUsbAttachmentNotifications.add(usbDevice);
        passReceivedUsbAttachmentsToEventLoop();
      }
    }
  }
}
 
開發者ID:ykarim,項目名稱:FTC2016,代碼行數:17,代碼來源:FtcRobotControllerActivity.java

示例15: onCreate

import android.hardware.usb.UsbManager; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.d(TAG, "onCreate");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    usbManager = (UsbManager) getApplicationContext().getSystemService(Context.USB_SERVICE);
    textView = (TextView)findViewById(R.id.mainTextView);
    scrollView = (ScrollView)findViewById(R.id.mainScrollView);


    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

    prepareFirmware();
}
 
開發者ID:amungo,項目名稱:AndroNut,代碼行數:27,代碼來源:MainActivity.java


注:本文中的android.hardware.usb.UsbManager類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。