当前位置: 首页>>代码示例>>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;未经允许,请勿转载。