本文整理匯總了Java中android.hardware.usb.UsbInterface.getInterfaceClass方法的典型用法代碼示例。如果您正苦於以下問題:Java UsbInterface.getInterfaceClass方法的具體用法?Java UsbInterface.getInterfaceClass怎麽用?Java UsbInterface.getInterfaceClass使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.hardware.usb.UsbInterface
的用法示例。
在下文中一共展示了UsbInterface.getInterfaceClass方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: enumerate
import android.hardware.usb.UsbInterface; //導入方法依賴的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()]);
}
示例2: isCdcDevice
import android.hardware.usb.UsbInterface; //導入方法依賴的package包/類
public static boolean isCdcDevice(UsbDevice device)
{
int iIndex = device.getInterfaceCount();
for(int i=0;i<=iIndex-1;i++)
{
UsbInterface iface = device.getInterface(i);
if(iface.getInterfaceClass() == UsbConstants.USB_CLASS_CDC_DATA)
return true;
}
return false;
}
示例3: requestDevicePermissionIfNecessary
import android.hardware.usb.UsbInterface; //導入方法依賴的package包/類
/**
* Request a device access permission if there is a MIDI interface in the device.
*
* @param device a USB device
*/
private void requestDevicePermissionIfNecessary(UsbDevice device) {
for (UsbDevice d : mRequestedDevices) {
if (d.getDeviceId() == device.getDeviceId()) {
// It is already requested.
return;
}
}
for (int i = 0; i < device.getInterfaceCount(); ++i) {
UsbInterface iface = device.getInterface(i);
if (iface.getInterfaceClass() == UsbConstants.USB_CLASS_AUDIO
&& iface.getInterfaceSubclass() == UsbMidiDeviceAndroid.MIDI_SUBCLASS) {
// There is at least one interface supporting MIDI.
mUsbManager.requestPermission(device,
PendingIntent.getBroadcast(ContextUtils.getApplicationContext(), 0,
new Intent(ACTION_USB_PERMISSION), 0));
mRequestedDevices.add(device);
break;
}
}
}
示例4: UsbMidiDeviceAndroid
import android.hardware.usb.UsbInterface; //導入方法依賴的package包/類
/**
* Constructs a UsbMidiDeviceAndroid.
* @param manager
* @param device The USB device which this object is assocated with.
*/
UsbMidiDeviceAndroid(UsbManager manager, UsbDevice device) {
mConnection = manager.openDevice(device);
mEndpointMap = new HashMap<Integer, UsbEndpoint>();
mRequestMap = new HashMap<UsbEndpoint, UsbRequest>();
for (int i = 0; i < device.getInterfaceCount(); ++i) {
UsbInterface iface = device.getInterface(i);
if (iface.getInterfaceClass() != UsbConstants.USB_CLASS_AUDIO ||
iface.getInterfaceSubclass() != MIDI_SUBCLASS) {
continue;
}
mConnection.claimInterface(iface, true);
for (int j = 0; j < iface.getEndpointCount(); ++j) {
UsbEndpoint endpoint = iface.getEndpoint(j);
if (endpoint.getDirection() == UsbConstants.USB_DIR_OUT) {
mEndpointMap.put(endpoint.getEndpointNumber(), endpoint);
}
}
}
}
示例5: findUsbInterface
import android.hardware.usb.UsbInterface; //導入方法依賴的package包/類
private UsbInterface findUsbInterface(UsbDevice device) {
//Log.d (TAG, "findAdbInterface " + device.getDeviceName());
int count = device.getInterfaceCount();
for (int i = 0; i < count; i++) {
UsbInterface intf = device.getInterface(i);
Log.d (TAG, "Interface " +i + " Class " +intf.getInterfaceClass() +" Prot " +intf.getInterfaceProtocol());
if (intf.getInterfaceClass() == 6
//255 && intf.getInterfaceSubclass() == 66 && intf.getInterfaceProtocol() == 1
) {
return intf;
}
}
return null;
}
示例6: findUsbInterface
import android.hardware.usb.UsbInterface; //導入方法依賴的package包/類
protected UsbInterface findUsbInterface(UsbDevice device) {
//Log.d (TAG, "findAdbInterface " + device.getDeviceName());
int count = device.getInterfaceCount();
for (int i = 0; i < count; i++) {
UsbInterface intf = device.getInterface(i);
Log.d (TAG, "Interface " +i + " Class " +intf.getInterfaceClass() +" Prot " +intf.getInterfaceProtocol());
if (intf.getInterfaceClass() == 6
//255 && intf.getInterfaceSubclass() == 66 && intf.getInterfaceProtocol() == 1
) {
return intf;
}
}
return null;
}
示例7: findAdbInterface
import android.hardware.usb.UsbInterface; //導入方法依賴的package包/類
static private UsbInterface findAdbInterface(UsbDevice device) {
Log.d(TAG, "findAdbInterface " + device);
int count = device.getInterfaceCount();
for (int i = 0; i < count; i++) {
UsbInterface intf = device.getInterface(i);
if (intf.getInterfaceClass() == 255 && intf.getInterfaceSubclass() == 66 &&
intf.getInterfaceProtocol() == 1) {
return intf;
}
}
return null;
}
示例8: findAdbInterface
import android.hardware.usb.UsbInterface; //導入方法依賴的package包/類
static private UsbInterface findAdbInterface(android.hardware.usb.UsbDevice device) {
int count = device.getInterfaceCount();
for (int i = 0; i < count; i++) {
UsbInterface intf = device.getInterface(i);
if (intf.getInterfaceClass() == 3
&& intf.getInterfaceSubclass() == 0
&& intf.getInterfaceProtocol() == 0) {
return intf;
}
}
return null;
}
示例9: isCamera
import android.hardware.usb.UsbInterface; //導入方法依賴的package包/類
/**
* Tests to see if a {@link android.hardware.usb.UsbDevice}
* supports the PTP protocol (typically used by digital cameras)
*
* @param device the device to test
* @return true if the device is a PTP device.
*/
static public boolean isCamera(UsbDevice device) {
int count = device.getInterfaceCount();
for (int i = 0; i < count; i++) {
UsbInterface intf = device.getInterface(i);
if (intf.getInterfaceClass() == UsbConstants.USB_CLASS_STILL_IMAGE &&
intf.getInterfaceSubclass() == 1 &&
intf.getInterfaceProtocol() == 1) {
return true;
}
}
return false;
}
示例10: UsbMidiDeviceAndroid
import android.hardware.usb.UsbInterface; //導入方法依賴的package包/類
/**
* Constructs a UsbMidiDeviceAndroid.
* @param manager
* @param device The USB device which this object is assocated with.
*/
UsbMidiDeviceAndroid(UsbManager manager, UsbDevice device) {
mConnection = manager.openDevice(device);
mEndpointMap = new SparseArray<UsbEndpoint>();
mRequestMap = new HashMap<UsbEndpoint, UsbRequest>();
mHandler = new Handler();
mUsbDevice = device;
mIsClosed = false;
mHasInputThread = false;
mNativePointer = 0;
for (int i = 0; i < device.getInterfaceCount(); ++i) {
UsbInterface iface = device.getInterface(i);
if (iface.getInterfaceClass() != UsbConstants.USB_CLASS_AUDIO
|| iface.getInterfaceSubclass() != MIDI_SUBCLASS) {
continue;
}
mConnection.claimInterface(iface, true);
for (int j = 0; j < iface.getEndpointCount(); ++j) {
UsbEndpoint endpoint = iface.getEndpoint(j);
if (endpoint.getDirection() == UsbConstants.USB_DIR_OUT) {
mEndpointMap.put(endpoint.getEndpointNumber(), endpoint);
}
}
}
// Start listening for input endpoints.
// This function will create and run a thread if there is USB-MIDI endpoints in the
// device. Note that because UsbMidiDevice is shared among all tabs and the thread
// will be terminated when the device is disconnected, at most one thread can be created
// for each connected USB-MIDI device.
startListen(device);
}
示例11: enumerateDevices
import android.hardware.usb.UsbInterface; //導入方法依賴的package包/類
/**
* Enumerates USB-MIDI devices.
* If there are devices having USB-MIDI interfaces, this function requests permission for
* accessing the device to the user.
* When the permission request is accepted or rejected onRequestDone will be called.
*
* If there are no USB-MIDI interfaces, this function returns false.
* @return true if some permission requests are in progress.
*/
@CalledByNative
boolean enumerateDevices(Context context) {
mUsbManager = (UsbManager)context.getSystemService(Context.USB_SERVICE);
Map<String, UsbDevice> devices = mUsbManager.getDeviceList();
PendingIntent pendingIntent = PendingIntent.getBroadcast(
context, 0, new Intent(ACTION_USB_PERMISSION), 0);
mRequestedDevices = new HashSet<UsbDevice>();
for (UsbDevice device : devices.values()) {
boolean found = false;
for (int i = 0; i < device.getInterfaceCount() && !found; ++i) {
UsbInterface iface = device.getInterface(i);
if (iface.getInterfaceClass() == UsbConstants.USB_CLASS_AUDIO &&
iface.getInterfaceSubclass() == UsbMidiDeviceAndroid.MIDI_SUBCLASS) {
found = true;
}
}
if (found) {
mUsbManager.requestPermission(device, pendingIntent);
mRequestedDevices.add(device);
}
}
if (mRequestedDevices.isEmpty()) {
// No USB-MIDI devices are found.
return false;
}
IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
if (ACTION_USB_PERMISSION.equals(intent.getAction())) {
onRequestDone(context, intent);
}
}
};
context.registerReceiver(mReceiver, filter);
return true;
}
示例12: findMidiInterface
import android.hardware.usb.UsbInterface; //導入方法依賴的package包/類
public static UsbInterface findMidiInterface(UsbDevice device) {
int count = device.getInterfaceCount();
for (int i = 0; i < count; i++) {
UsbInterface usbIf = device.getInterface(i);
if (usbIf.getInterfaceClass() == 1 && usbIf.getInterfaceSubclass() == 3) {
return usbIf;
}
}
return null;
}
示例13: refreshDevice
import android.hardware.usb.UsbInterface; //導入方法依賴的package包/類
private final void refreshDevice() {
if (mUsbMonitor == null) {
return;
}
camList = null;
List<UsbDevice> allDev = mUsbMonitor.getDeviceList();
if (allDev.size() <= 0) {
return;
}
for (UsbDevice d : allDev) {
boolean isVideoDev = false;
if (d.getInterfaceCount() <= 0) {
if (d.getDeviceClass() == 239 && d.getDeviceSubclass() == 2) {
isVideoDev = true;
}
} else {
for (int i = 0; i < d.getInterfaceCount(); i++) {
UsbInterface in = d.getInterface(0);
if (in == null) {
continue;
}
if (in.getInterfaceClass() == 14) {
isVideoDev = true;
break;
}
}
}
if (isVideoDev) {
if (camList == null) {
camList = new ArrayList<UsbDevice>();
}
camList.add(d);
}
}
if (camList == null) {
System.out.println("v4l no device");
} else {
Collections.sort(camList, new Comparator<UsbDevice>(){
@Override
public int compare(UsbDevice left, UsbDevice right) {
return (left.getDeviceName().compareTo(right.getDeviceName()));
}
});
}
}
示例14: filterDevice
import android.hardware.usb.UsbInterface; //導入方法依賴的package包/類
private boolean filterDevice(UsbDevice device, JSONArray filters) throws JSONException {
if (filters == null) {
return true;
}
Log.d(TAG, "filtering " + filters);
for (int filterIdx = 0; filterIdx < filters.length(); filterIdx++) {
JSONObject filter = filters.getJSONObject(filterIdx);
int vendorId = filter.optInt("vendorId", -1);
if (vendorId != -1) {
if (device.getVendorId() != vendorId) {
continue;
}
}
int productId = filter.optInt("productId", -1);
if (productId != -1) {
if (device.getProductId() != productId) {
continue;
}
}
int interfaceClass = filter.optInt("interfaceClass", -1);
int interfaceSubclass = filter.optInt("interfaceSubclass", -1);
int interfaceProtocol = filter.optInt("interfaceProtocol", -1);
if (interfaceClass == -1 && interfaceSubclass == -1 && interfaceProtocol == -1) {
return true;
}
int interfaceCount = device.getInterfaceCount();
for (int interfaceIdx = 0; interfaceIdx < interfaceCount; interfaceIdx++) {
UsbInterface usbInterface = device.getInterface(interfaceIdx);
if (interfaceClass != -1) {
if (interfaceClass != usbInterface.getInterfaceClass()) {
continue;
}
}
if (interfaceSubclass != -1) {
if (interfaceSubclass != usbInterface.getInterfaceSubclass()) {
continue;
}
}
if (interfaceProtocol != -1) {
if (interfaceProtocol != usbInterface.getInterfaceProtocol()) {
continue;
}
}
return true;
}
}
return false;
}
示例15: open
import android.hardware.usb.UsbInterface; //導入方法依賴的package包/類
public synchronized void open() throws IOException {
if (usbDevice == null) throw new IllegalArgumentException("Device can't be null");
if (usbInterface == null) {
for (int i = 0; i < usbDevice.getInterfaceCount(); i++) {
UsbInterface usbIf = usbDevice.getInterface(i);
if (usbIf.getInterfaceClass() == UsbConstants.USB_CLASS_CSCID) {
usbInterface = usbIf;
}
}
if (usbInterface == null)
throw new IllegalStateException("The device hasn't a smart card reader");
}
usbConnection = usbManager.openDevice(usbDevice);
usbConnection.claimInterface(usbInterface, true);
sequence = 0;
//Get the interfaces
for (int i = 0; i < usbInterface.getEndpointCount(); i++) {
UsbEndpoint usbEp = usbInterface.getEndpoint(i);
if (usbEp.getDirection() == UsbConstants.USB_DIR_IN && usbEp.getType() == UsbConstants.USB_ENDPOINT_XFER_INT) {
usbInterrupt = usbEp;
}
if (usbEp.getDirection() == UsbConstants.USB_DIR_OUT && usbEp.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) {
usbOut = usbEp;
}
if (usbEp.getDirection() == UsbConstants.USB_DIR_IN && usbEp.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) {
usbIn = usbEp;
}
}
//check for pinPad
CCIDDescriptor desc = CCIDDescriptor.Parse(usbConnection.getRawDescriptors()).get(usbInterface.getId());
pinPad = desc.getPinSupports().contains(CCIDDescriptor.PINSupport.Verification);
supportApdu = desc.getFeatures().contains(CCIDDescriptor.Feature.ShortAPDU) || desc.getFeatures().contains(CCIDDescriptor.Feature.ShortAndExtendedAPDU);
autoInit = desc.getFeatures().contains(CCIDDescriptor.Feature.AutoParamConfigViaATR);
//Listen for state changes
setupStateListener();
}