本文整理匯總了Java中android.hardware.usb.UsbDevice類的典型用法代碼示例。如果您正苦於以下問題:Java UsbDevice類的具體用法?Java UsbDevice怎麽用?Java UsbDevice使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
UsbDevice類屬於android.hardware.usb包,在下文中一共展示了UsbDevice類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: showListOfDevices
import android.hardware.usb.UsbDevice; //導入依賴的package包/類
void showListOfDevices(Context context) {
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(context);
if (getDeviceList().isEmpty()) {
alertBuilder.setTitle(R.string.usb_connect_title)
.setPositiveButton(R.string.ok, null);
} else {
alertBuilder.setTitle(R.string.usb_select_title);
List<CharSequence> list = new LinkedList<>();
for (UsbDevice usbDevice : getDeviceList().values()) {
list.add("devID:" + usbDevice.getDeviceId() + " VID:" + Integer.toHexString(usbDevice.getVendorId()) + " PID:" + Integer.toHexString(usbDevice.getProductId()) + " " + usbDevice.getDeviceName());
}
final CharSequence devicesName[] = new CharSequence[getDeviceList().size()];
list.toArray(devicesName);
alertBuilder.setItems(devicesName, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
UsbDevice device = (UsbDevice) getDeviceList().values().toArray()[which];
mUsbManager.requestPermission(device, mPermissionIntent);
}
});
}
alertBuilder.setCancelable(true);
adScaleWarning = alertBuilder.show();
}
示例2: produceInitiator
import android.hardware.usb.UsbDevice; //導入依賴的package包/類
static public BaselineInitiator produceInitiator(UsbDevice device, UsbManager usbManager) throws PTPException {
BaselineInitiator bi;
CameraDetector cd = new CameraDetector(device);
if (cd.getSupportedVendorId() == CameraDetector.VENDOR_ID_CANON) {
Log.d(TAG, "Device is CANON, open EOSInitiator");
bi = new EosInitiator(device, usbManager.openDevice(device));
} else if (cd.getSupportedVendorId() == CameraDetector.VENDOR_ID_NIKON) {
Log.d(TAG, "Device is Nikon, open NikonInitiator");
bi = new NikonInitiator(device, usbManager.openDevice(device));
} else if (cd.getSupportedVendorId() == CameraDetector.VENDOR_ID_SONY) {
Log.d(TAG, "Device is Sony, open SonyInitiator");
bi = new SonyInitiator(device, usbManager.openDevice(device));
} else /* if (cd.getSupportedVendorId() == CameraDetector.VENDOR_ID_OTHER) */ {
Log.d(TAG, "Unkown device, open BaselineInitiator");
bi = new BaselineInitiator (device, usbManager.openDevice(device));
}
return bi;
}
示例3: findUsbSerialPort
import android.hardware.usb.UsbDevice; //導入依賴的package包/類
private UsbSerialPort findUsbSerialPort(ConfigStorage.SerialPortIdentifier identifier) {
final List<UsbSerialDriver> drivers =
UsbSerialProber.getDefaultProber().findAllDrivers(mUsbManager);
for (final UsbSerialDriver driver : drivers) {
for (final UsbSerialPort port : driver.getPorts()) {
UsbDevice device = port.getDriver().getDevice();
if (device != null
&& device.getVendorId() == identifier.getVendorId()
&& device.getProductId() == identifier.getProductId()
&& Objects.equals(device.getSerialNumber(), identifier.getSerialNumber())) {
return port;
}
}
}
return null;
}
示例4: setupUsb
import android.hardware.usb.UsbDevice; //導入依賴的package包/類
protected void setupUsb(UsbDevice device) {
UsbInterface inf = device.getInterface(0);
UsbDeviceConnection conn = mUsbManager.openDevice(device);
if (conn == null) {
Log.wtf("MainActivity", "unable to open device?");
return;
}
if (!conn.claimInterface(inf, true)) {
conn.close();
Log.wtf("MainActivity", "unable to claim interface!");
return;
}
mBlinkDevice = device;
mBlinkConn = conn;
}
示例5: destroy
import android.hardware.usb.UsbDevice; //導入依賴的package包/類
public void destroy() {
unregister();
final Set<UsbDevice> keys = mCtrlBlocks.keySet();
if (keys != null) {
UsbControlBlock ctrlBlock;
try {
for (final UsbDevice key: keys) {
ctrlBlock = mCtrlBlocks.remove(key);
ctrlBlock.close();
}
} catch (final Exception e) {
Log.e(TAG, "destroy:", e);
}
mCtrlBlocks.clear();
}
}
示例6: getAllUsbDevices
import android.hardware.usb.UsbDevice; //導入依賴的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("--------");
}
}
示例7: setAdbInterface
import android.hardware.usb.UsbDevice; //導入依賴的package包/類
private boolean setAdbInterface(UsbDevice device, UsbInterface intf) {
if (mDeviceConnection != null) {
if (mInterface != null) {
mDeviceConnection.releaseInterface(mInterface);
mInterface = null;
}
mDeviceConnection.close();
mDevice = null;
mDeviceConnection = null;
}
if (device != null && intf != null) {
UsbDeviceConnection connection = mManager.openDevice(device);
if (connection != null) {
log("open succeeded");
if (connection.claimInterface(intf, false)) {
log("claim interface succeeded");
mDevice = device;
mDeviceConnection = connection;
mInterface = intf;
mAdbDevice = new AdbDevice(this, mDeviceConnection, intf);
log("call start");
mAdbDevice.start();
return true;
} else {
log("claim interface failed");
connection.close();
}
} else {
log("open failed");
}
}
if (mDeviceConnection == null && mAdbDevice != null) {
mAdbDevice.stop();
mAdbDevice = null;
}
return false;
}
示例8: probeDevice
import android.hardware.usb.UsbDevice; //導入依賴的package包/類
/**
* Probes a single device for a compatible driver.
*
* @param usbDevice the usb device to probe
*
* @return a new {@link UsbSerialDriver} compatible with this device, or
* {@code null} if none available.
*/
@Keep
public UsbSerialDriver probeDevice(final UsbDevice usbDevice) {
final int vendorId = usbDevice.getVendorId();
final int productId = usbDevice.getProductId();
final Class<? extends UsbSerialDriver> driverClass = mProbeTable.findDriver(vendorId, productId);
if (driverClass != null) {
final UsbSerialDriver driver;
try {
final Constructor<? extends UsbSerialDriver> constructor = driverClass.getConstructor(UsbDevice.class);
driver = constructor.newInstance(usbDevice);
} catch (Exception e) {
throw new RuntimeException(e);
}
return driver;
}
return null;
}
示例9: readDevice
import android.hardware.usb.UsbDevice; //導入依賴的package包/類
/**
* Enumerate the endpoints and interfaces on the connected device.
*
* @param device Device to query.
* @return String description of the device configuration.
*/
public static String readDevice(UsbDevice device) {
StringBuilder sb = new StringBuilder();
sb.append("Device Name: " + device.getDeviceName() + "\n");
sb.append(String.format(
"Device Class: %s -> Subclass: 0x%02x -> Protocol: 0x%02x\n",
nameForClass(device.getDeviceClass()),
device.getDeviceSubclass(), device.getDeviceProtocol()));
for (int i = 0; i < device.getInterfaceCount(); i++) {
UsbInterface intf = device.getInterface(i);
sb.append(String.format(Locale.US,
"-- Interface %d Class: %s -> Subclass: 0x%02x -> Protocol: 0x%02x\n",
intf.getId(),
nameForClass(intf.getInterfaceClass()),
intf.getInterfaceSubclass(),
intf.getInterfaceProtocol()));
sb.append(String.format(Locale.US, " -- Endpoint Count: %d\n",
intf.getEndpointCount()));
}
return sb.toString();
}
示例10: onReceive
import android.hardware.usb.UsbDevice; //導入依賴的package包/類
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) {
afterGetUsbPermission(null);
} else if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
disConnectDevice();
} else if (ACTION_USB_PERMISSION.equals(action)) {
synchronized (this) {
UsbDevice usbDevice = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
//user choose YES for your previously popup window asking for grant perssion for this usb device
if (onUsbChangeListener != null) {
onUsbChangeListener.onPermissionGranted();
}
if (null != usbDevice) {
afterGetUsbPermission(usbDevice);
}
} else {
//user choose NO for your previously popup window asking for grant perssion for this usb device
if (onUsbChangeListener != null) {
onUsbChangeListener.onPermissionRefused();
}
}
}
}
}
示例11: onReceive
import android.hardware.usb.UsbDevice; //導入依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (ACTION_USB_PERMISSION.equals(action) || ACTION_USB_PERMISSION_AUTOCONNECT.equals(action)) {
synchronized (this) {
UsbDevice device = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
if (!intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
Log.d(TAG, "permission denied for mDevice " + device);
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setMessage(R.string.permission_denied)
.setTitle(R.string.permission_denied_title);
builder.show();
} else if (ACTION_USB_PERMISSION_AUTOCONNECT.equals(action)) {
// permission was granted, and now we need to hit up the connect button again
btnConnect(null);
}
}
}
}
示例12: Af9035DvbDevice
import android.hardware.usb.UsbDevice; //導入依賴的package包/類
Af9035DvbDevice(UsbDevice usbDevice, Context context, DeviceFilter filter) throws DvbException {
super(usbDevice, context, filter, DvbDemux.DvbDmxSwfilter());
iface = usbDevice.getInterface(0);
controlEndpointIn = iface.getEndpoint(0);
controlEndpointOut = iface.getEndpoint(1);
endpoint = iface.getEndpoint(2);
// Endpoint 3 is a TS USB_DIR_IN endpoint with address 0x85
// but I don't know what it is used for
if (controlEndpointIn.getAddress() != 0x81 || controlEndpointIn.getDirection() != USB_DIR_IN)
throw new DvbException(DVB_DEVICE_UNSUPPORTED, resources.getString(R.string.unexpected_usb_endpoint));
if (controlEndpointOut.getAddress() != 0x02 || controlEndpointOut.getDirection() != USB_DIR_OUT)
throw new DvbException(DVB_DEVICE_UNSUPPORTED, resources.getString(R.string.unexpected_usb_endpoint));
if (endpoint.getAddress() != 0x84 || endpoint.getDirection() != USB_DIR_IN)
throw new DvbException(DVB_DEVICE_UNSUPPORTED, resources.getString(R.string.unexpected_usb_endpoint));
}
示例13: getUsbDvbDevices
import android.hardware.usb.UsbDevice; //導入依賴的package包/類
/**
* Gets a {@link DvbDevice} if a supported DVB USB dongle is connected to the system.
* If multiple dongles are connected, a {@link Collection} would be returned
* @param context a context for obtaining {@link Context#USB_SERVICE}
* @return a {@link Collection} of available {@link DvbDevice} devices. Can be empty.
*/
public static List<DvbDevice> getUsbDvbDevices(Context context) throws DvbException {
List<DvbDevice> availableDvbDevices = new ArrayList<>();
UsbManager manager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
Collection<UsbDevice> availableDevices = manager.getDeviceList().values();
DvbException lastException = null;
for (UsbDevice usbDevice : availableDevices) {
try {
DvbDevice frontend = getDvbUsbDeviceFor(usbDevice, context);
if (frontend != null) availableDvbDevices.add(frontend);
} catch (DvbException e) {
// Failed to initialize this device, try next and capture exception
e.printStackTrace();
lastException = e;
}
}
if (availableDvbDevices.isEmpty()) {
if (lastException != null) throw lastException;
}
return availableDvbDevices;
}
示例14: onStatusChanged
import android.hardware.usb.UsbDevice; //導入依賴的package包/類
@Override
public void onStatusChanged(final UsbDevice device, int status) {
Log.i(TAG, "onStatusChanged:" + status);
if(status == FaBoUsbConst.ATTACHED) {
mDevice = device;
}
else if(status == FaBoUsbConst.CONNECTED) {
Log.i(TAG, "Write");
mDevice = device;
this.runOnUiThread(new Runnable() {
@Override
public void run() {
mEditText.setText("Connected " + device.getDeviceName());
}
});
}
}
示例15: passReceivedUsbAttachmentsToEventLoop
import android.hardware.usb.UsbDevice; //導入依賴的package包/類
protected void passReceivedUsbAttachmentsToEventLoop() {
if (this.eventLoop != null) {
for (;;) {
UsbDevice usbDevice = receivedUsbAttachmentNotifications.poll();
if (usbDevice == null)
break;
this.eventLoop.onUsbDeviceAttached(usbDevice);
}
}
else {
// Paranoia: we don't want the pending list to grow without bound when we don't
// (yet) have an event loop
while (receivedUsbAttachmentNotifications.size() > 100) {
receivedUsbAttachmentNotifications.poll();
}
}
}