當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。