当前位置: 首页>>代码示例>>Java>>正文


Java UsbManager.getDeviceList方法代码示例

本文整理汇总了Java中android.hardware.usb.UsbManager.getDeviceList方法的典型用法代码示例。如果您正苦于以下问题:Java UsbManager.getDeviceList方法的具体用法?Java UsbManager.getDeviceList怎么用?Java UsbManager.getDeviceList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.hardware.usb.UsbManager的用法示例。


在下文中一共展示了UsbManager.getDeviceList方法的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: 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

示例3: getAllUsbDevices

import android.hardware.usb.UsbManager; //导入方法依赖的package包/类
public void getAllUsbDevices() {
    UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
    HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
    Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
    int i = 0;
    while(deviceIterator.hasNext()){
        i++;
        UsbDevice device = deviceIterator.next();
        log("--------");
        log("设备 : " + i);
        log("device id : " + device.getDeviceId());
        log("name : " + device.getDeviceName());
        log("class : " + device.getDeviceClass());
        log("subclass : " + device.getDeviceSubclass());
        log("vendorId : " + device.getVendorId());
        // log("version : " + device.getVersion() );
        log("serial number : " + device.getSerialNumber() );
        log("interface count : " + device.getInterfaceCount());
        log("device protocol : " + device.getDeviceProtocol());
        log("--------");

    }
}
 
开发者ID:iyundong,项目名称:InstantUpload,代码行数:24,代码来源:ControllerActivity.java

示例4: connectMTPDevice

import android.hardware.usb.UsbManager; //导入方法依赖的package包/类
void connectMTPDevice(){
    UsbManager usbManager = (UsbManager)getSystemService(Context.USB_SERVICE);
    Log.v("usb manager get", usbManager.toString());
    Map<String, UsbDevice> map = usbManager.getDeviceList();
    Set<String> set = map.keySet();

    if (set.size() == 0) {
        log("无法获取设备信息,请确保相机已经连接或者处于激活状态");
    }

    for (String s : set) {
        UsbDevice device = map.get(s);
        if( !usbManager.hasPermission(device) ){
            registerUsbPermission(device);
            return;
        }else {
            performConnect(device);
        }
    }
}
 
开发者ID:iyundong,项目名称:InstantUpload,代码行数:21,代码来源:ControllerActivity.java

示例5: isUsbTunerConnected

import android.hardware.usb.UsbManager; //导入方法依赖的package包/类
/**
 * See if any USB tuner hardware is attached in the system.
 *
 * @param context {@link Context} instance
 * @return {@code true} if any tuner device we support is plugged in
 */
private boolean isUsbTunerConnected(Context context) {
    UsbManager manager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
    Map<String, UsbDevice> deviceList = manager.getDeviceList();
    for (UsbDevice device : deviceList.values()) {
        if (DEBUG) {
            Log.d(TAG, "Device: " + device);
        }
        for (TunerDevice tuner : TUNER_DEVICES) {
            if (tuner.equals(device)) {
                Log.i(TAG, "Tuner found");
                return true;
            }
        }
    }
    return false;
}
 
开发者ID:trevd,项目名称:android_packages_apps_tv,代码行数:23,代码来源:TunerInputController.java

示例6: isG4Connected

import android.hardware.usb.UsbManager; //导入方法依赖的package包/类
static public boolean isG4Connected(Context c) {
    UsbManager manager = (UsbManager) c.getSystemService(Context.USB_SERVICE);
    HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
    Log.i("USB DEVICES = ", deviceList.toString());
    Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
    Log.i("USB DEVICES = ", String.valueOf(deviceList.size()));

    while (deviceIterator.hasNext()) {
        UsbDevice device = deviceIterator.next();
        if (device.getVendorId() == 8867 && device.getProductId() == 71
                && device.getDeviceClass() == 2 && device.getDeviceSubclass() == 0
                && device.getDeviceProtocol() == 0) {
            Log.i("CALIBRATION-CHECK-IN: ", "Dexcom Found!");
            return true;
        }
    }
    return false;
}
 
开发者ID:LadyViktoria,项目名称:wearDrip,代码行数:19,代码来源:SyncingService.java

示例7: findDexcom

import android.hardware.usb.UsbManager; //导入方法依赖的package包/类
public UsbDevice findDexcom() {
    Log.i("CALIBRATION-CHECK-IN: ", "Searching for dexcom");
    mUsbManager = (UsbManager) getApplicationContext().getSystemService(Context.USB_SERVICE);
    Log.i("USB MANAGER = ", mUsbManager.toString());
    HashMap<String, UsbDevice> deviceList = mUsbManager.getDeviceList();
    Log.i("USB DEVICES = ", deviceList.toString());
    Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
    Log.i("USB DEVICES = ", String.valueOf(deviceList.size()));

    while (deviceIterator.hasNext()) {
        UsbDevice device = deviceIterator.next();
        if (device.getVendorId() == 8867 && device.getProductId() == 71
                && device.getDeviceClass() == 2 && device.getDeviceSubclass() == 0
                && device.getDeviceProtocol() == 0) {
            dexcom = device;
            Log.i("CALIBRATION-CHECK-IN: ", "Dexcom Found!");
            return device;
        } else {
            Log.w("CALIBRATION-CHECK-IN: ", "that was not a dexcom (I dont think)");
        }
    }
    return null;
}
 
开发者ID:LadyViktoria,项目名称:wearDrip,代码行数:24,代码来源:SyncingService.java

示例8: isG4Connected

import android.hardware.usb.UsbManager; //导入方法依赖的package包/类
static public boolean isG4Connected(Context c){
    UsbManager manager = (UsbManager) c.getSystemService(Context.USB_SERVICE);
    HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
    Log.i("USB DEVICES = ", deviceList.toString());
    Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
    Log.i("USB DEVICES = ", String.valueOf(deviceList.size()));

    while(deviceIterator.hasNext()){
        UsbDevice device = deviceIterator.next();
        if (device.getVendorId() == 8867 && device.getProductId() == 71
                && device.getDeviceClass() == 2 && device.getDeviceSubclass() ==0
                && device.getDeviceProtocol() == 0){
            Log.i("CALIBRATION-CHECK-IN: ", "Dexcom Found!");
            return true;
        }
    }
    return false;
}
 
开发者ID:NightscoutFoundation,项目名称:xDrip,代码行数:19,代码来源:SyncingService.java

示例9: findDexcom

import android.hardware.usb.UsbManager; //导入方法依赖的package包/类
public UsbDevice findDexcom() {
    Log.i("CALIBRATION-CHECK-IN: ", "Searching for dexcom");
    mUsbManager = (UsbManager) getApplicationContext().getSystemService(Context.USB_SERVICE);
    Log.i("USB MANAGER = ", mUsbManager.toString());
    HashMap<String, UsbDevice> deviceList = mUsbManager.getDeviceList();
    Log.i("USB DEVICES = ", deviceList.toString());
    Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
    Log.i("USB DEVICES = ", String.valueOf(deviceList.size()));

    while(deviceIterator.hasNext()){
        UsbDevice device = deviceIterator.next();
        if (device.getVendorId() == 8867 && device.getProductId() == 71
                && device.getDeviceClass() == 2 && device.getDeviceSubclass() ==0
                && device.getDeviceProtocol() == 0){
            dexcom = device;
            Log.i("CALIBRATION-CHECK-IN: ", "Dexcom Found!");
            return device;
        } else {
            Log.w("CALIBRATION-CHECK-IN: ", "that was not a dexcom (I dont think)");
        }
    }
    return null;
}
 
开发者ID:NightscoutFoundation,项目名称:xDrip,代码行数:24,代码来源:SyncingService.java

示例10: getUSBList

import android.hardware.usb.UsbManager; //导入方法依赖的package包/类
/**
 * Name:        getUSBStatus
 * Description: Determines the name of the USB devices currently attached
 *
 * @return      String array of the names of the USB Devices attached
 */
String [] getUSBList() {
    UsbManager manager =
            (UsbManager) context.getSystemService(Context.USB_SERVICE);

    HashMap<String, UsbDevice> deviceMap = manager.getDeviceList();
    String [] deviceList = new String [deviceMap.size()];

    int i = 0;
    for (UsbDevice devices : deviceMap.values()) {
        deviceList[i] = deviceMap.get(devices).getDeviceName();
        i++;
    }

    return deviceList;
}
 
开发者ID:IOT-410c,项目名称:IOT-DB410c-Course-3,代码行数:22,代码来源:SystemInfo.java

示例11: launchOpenBciService

import android.hardware.usb.UsbManager; //导入方法依赖的package包/类
private void launchOpenBciService() {
    UsbManager usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
    UsbDevice usbDevice = null;

    HashMap<String, UsbDevice> deviceList = usbManager.getDeviceList();

    for (Map.Entry<String, UsbDevice> entry : deviceList.entrySet()) {
        UsbDevice device = entry.getValue();
        if (device.getVendorId() == OpenBci.VENDOR_ID) {
            usbDevice = device;
        }
    }

    if (null == usbDevice) {
        Log.d(TAG, "no device found");
    } else {
        Intent intent = new Intent(getApplicationContext(), BrainDroidService.class);
        intent.putExtra(UsbManager.EXTRA_DEVICE, usbDevice);
        startService(intent);
    }
}
 
开发者ID:florian-f,项目名称:braindroid,代码行数:22,代码来源:MainActivity.java

示例12: getUSBList

import android.hardware.usb.UsbManager; //导入方法依赖的package包/类
/**
 * Name:        getUSBList
 * Description: Determines the name of the USB devices currently attached
 *
 * @return      String array of the names of the USB Devices attached
 */
String [] getUSBList() {
    UsbManager manager =
            (UsbManager) context.getSystemService(Context.USB_SERVICE);

    HashMap<String, UsbDevice> deviceMap = manager.getDeviceList();
    String [] deviceList = new String [deviceMap.size()];

    int i = 0;
    for (UsbDevice devices : deviceMap.values()) {
        deviceList[i] = deviceMap.get(devices).getDeviceName();
        i++;
    }

    return deviceList;
}
 
开发者ID:IOT-410c,项目名称:IOT-DB410c-Course-2,代码行数:22,代码来源:SystemInfo.java

示例13: retrieveAvailableUsbDevices

import android.hardware.usb.UsbManager; //导入方法依赖的package包/类
public static List<RtlSdrDevice> retrieveAvailableUsbDevices(final Context context) {
    final List<RtlSdrDevice> result = new LinkedList<>();
    if (usbSupported) {
        final Object usbManagerObj=context.getSystemService(Context.USB_SERVICE);
        if (usbManagerObj instanceof UsbManager) {
            final UsbManager manager = (UsbManager) usbManagerObj;
            retrieveSupportedDevices(context.getResources());

            final HashMap<String, UsbDevice> deviceList = manager.getDeviceList();

            for (final Map.Entry<String, UsbDevice> desc : deviceList.entrySet()) {
                final UsbDevice candidate = desc.getValue();
                final Pair<Integer, Integer> candidatePair = new Pair<>(candidate.getVendorId(), candidate.getProductId());

                SupportedDevice device = null;
                for (int i = 0; i < supportedDevices.size() && device == null; i++) {
                    final SupportedDevice supportedDevice = supportedDevices.get(i);
                    if (supportedDevice.getVendorAndProductId().equals(candidatePair)) {
                        device = supportedDevice;
                    }
                }

                if (device != null) {
                    final String friendlyName = candidate.getDeviceName() + " " + device.getDescription() + " (" + candidate.getVendorId() + ":" + candidate.getProductId() + ")";
                    result.add(new RtlSdrDevice(candidate, friendlyName));
                }
            }
        }
    }
    return result;
}
 
开发者ID:videgro,项目名称:Ships,代码行数:32,代码来源:UsbUtils.java

示例14: start

import android.hardware.usb.UsbManager; //导入方法依赖的package包/类
public void start(int bauds, String endline, onReadCB callbackfn) {
        getAppRunner().whatIsRunning.add(this);

        mEndLine = endline;

        if (!started) {
            started = true;
            MLog.d("PArduino", "start ");

            UsbManager manager = (UsbManager) getContext().getSystemService(Context.USB_SERVICE);
            HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
            Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
            while (deviceIterator.hasNext()) {
                UsbDevice device = deviceIterator.next();
                MLog.network(getContext(), TAG, "USB " + device.getDeviceName());
                //your code
            }

            mPhysicaloid = new Physicaloid(getContext());
            open();
            mPhysicaloid.setBaudrate(bauds);

//            int mFlowControl = UartConfig.FLOW_CONTROL_OFF;
//            int mDataBits = UartConfig.DATA_BITS8;
//            int mStopBits = UartConfig.STOP_BITS1;
//            int mParity = UartConfig.PARITY_NONE;
//
//            boolean dtrOn=false;
//            boolean rtsOn=false;
//            if(mFlowControl == UartConfig.FLOW_CONTROL_ON) {
//                dtrOn = true;
//                rtsOn = true;
//            }
            //    mPhysicaloid.setConfig(new UartConfig(bauds, mDataBits, mStopBits, mParity, dtrOn, rtsOn));


            onRead(callbackfn);
        }
    }
 
开发者ID:victordiaz,项目名称:phonk,代码行数:40,代码来源:PArduino.java

示例15: findDevice

import android.hardware.usb.UsbManager; //导入方法依赖的package包/类
/**
 * Find usb device.
 */
public void findDevice() {

    // Get UsbManager.
    UsbManager manager = (UsbManager) this.mContext.getSystemService(this.mContext.USB_SERVICE);

    // check vid and pid.
    HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
    Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
    while (deviceIterator.hasNext()) {
        UsbDevice device = deviceIterator.next();
        checkDevice(device);
    }
}
 
开发者ID:FaBoPlatform,项目名称:FaBo-Serial-Kit,代码行数:17,代码来源:FaBoUsbManager.java


注:本文中的android.hardware.usb.UsbManager.getDeviceList方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。