本文整理汇总了Java中android.hardware.usb.UsbManager.hasPermission方法的典型用法代码示例。如果您正苦于以下问题:Java UsbManager.hasPermission方法的具体用法?Java UsbManager.hasPermission怎么用?Java UsbManager.hasPermission使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.hardware.usb.UsbManager
的用法示例。
在下文中一共展示了UsbManager.hasPermission方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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);
}
}
}
示例3: setup
import android.hardware.usb.UsbManager; //导入方法依赖的package包/类
public void setup(Context context) {
mManager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
UsbAccessory[] accessoryList = mManager.getAccessoryList();
PendingIntent mPermissionIntent = PendingIntent.getBroadcast(context, 0,
new Intent(ACTION_USB_PERMISSION), 0);
IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
context.registerReceiver(mUsbReceiver, filter);
mManager.requestPermission(accessoryList[0], mPermissionIntent);
if (accessoryList[0] != null) {
mAccessory = accessoryList[0];
if (mManager.hasPermission(mAccessory)) {
openAccessory(mAccessory);
}
}
}
示例4: checkForDJIAccessory
import android.hardware.usb.UsbManager; //导入方法依赖的package包/类
public void checkForDJIAccessory() {
mUsbManager = (UsbManager) BridgeApplication.getInstance().getSystemService(Context.USB_SERVICE);
UsbAccessory[] accessoryList = mUsbManager.getAccessoryList();
if (accessoryList != null
&& accessoryList.length > 0
&& !TextUtils.isEmpty(accessoryList[0].getManufacturer())
&& accessoryList[0].getManufacturer().equals("DJI")) {
BridgeApplication.getInstance().getBus().post(new RCConnectionEvent(true));
//Check permission
mAccessory = accessoryList[0];
if (mUsbManager.hasPermission(mAccessory)) {
Log.d(TAG, "RC CONNECTED");
} else {
Log.d(TAG, "NO Permission to USB Accessory");
DJIRemoteLogger.e(TAG, "NO Permission to USB Accessory");
//mUsbManager.requestPermission(mAccessory, null);
}
} else {
BridgeApplication.getInstance().getBus().post(new RCConnectionEvent(false));
Log.d(TAG, "RC DISCONNECTED");
}
}
示例5: openDeviceAsync
import android.hardware.usb.UsbManager; //导入方法依赖的package包/类
@ReactMethod
public void openDeviceAsync(ReadableMap deviceObject, Promise p) {
try {
int prodId = deviceObject.getInt("productId");
UsbManager manager = getUsbManager();
UsbSerialDriver driver = getUsbSerialDriver(prodId, manager);
if (manager.hasPermission(driver.getDevice())) {
WritableMap usd = createUsbSerialDevice(manager, driver);
p.resolve(usd);
} else {
requestUsbPermission(manager, driver.getDevice(), p);
}
} catch (Exception e) {
p.reject(e);
}
}
示例6: openUsbConnection
import android.hardware.usb.UsbManager; //导入方法依赖的package包/类
@Override
protected void openUsbConnection() throws IOException {
registerUsbPermissionBroadcastReceiver();
// Get UsbManager from Android.
UsbManager manager = (UsbManager) mContext.getSystemService(Context.USB_SERVICE);
//Get the list of available devices
List<UsbDevice> availableDevices = UsbSerialProber.getAvailableSupportedDevices(manager);
if(availableDevices.isEmpty()){
Log.d("USB", "No Devices found");
throw new IOException("No Devices found");
}
//Pick the first device
UsbDevice device = availableDevices.get(0);
if(manager.hasPermission(device)){
openUsbDevice(device);
}
else{
//TODO: complete implementation
// manager.requestPermission(device, usbPermissionIntent);
throw new IOException("No permission to access usb device " + device.getDeviceName());
}
}
示例7: connect
import android.hardware.usb.UsbManager; //导入方法依赖的package包/类
@Override
public void connect() {
Log.d(LOG_TAG, "connect:");
if (deviceConnection != null) {
Log.e(LOG_TAG, "connect: Already connected!");
return;
} else if (device.getInterfaceCount() == 0) {
// 2016.12.17 [email protected]
// If you got here and you don't know why, the following link might be helpful.
// https://code.google.com/p/android/issues/detail?id=159529
throw new UsbDeviceHasNoInterfaceException("The USB device(" + device.getDeviceName() + ") has no USB interface!");
}
registerReceiver();
final UsbManager usbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
if (usbManager.hasPermission(device)) {
startConnecting();
} else {
// Ask permission for USB connection
PendingIntent intent = PendingIntent.getBroadcast(context, 0, new Intent(ACTION_USB_PERMISSION), 0);
Log.d(LOG_TAG, "Requesting permission for USB device '" + device.getDeviceName() + "'...");
usbManager.requestPermission(device, intent);
}
}
示例8: obtainFdFor
import android.hardware.usb.UsbManager; //导入方法依赖的package包/类
public static Future<UsbDeviceConnection> obtainFdFor(Context context, UsbDevice usbDevice) {
UsbManager manager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
if (!manager.hasPermission(usbDevice)) {
AsyncFuture<UsbDeviceConnection> task = new AsyncFuture<>();
registerNewBroadcastReceiver(context, usbDevice, task);
manager.requestPermission(usbDevice, PendingIntent.getBroadcast(context, 0, new Intent(ACTION_USB_PERMISSION), 0));
return task;
} else {
return new CompletedFuture<>(manager.openDevice(usbDevice));
}
}
示例9: onStartCommand
import android.hardware.usb.UsbManager; //导入方法依赖的package包/类
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (App.isDebug()) {
Log.d(TAG, "onStartCommand");
}
usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
if (intent != null) {
if (App.getPrefs().getBoolean("usb", true)) {
UsbDevice usbDevice = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
String usbDevicePrefs = App.getPrefs().getString("usbDevice", "");
if (usbDevice != null && usbManager.hasPermission(usbDevice)
&& App.getPrefs().getBoolean("usb", true)
&& (usbDevicePrefs.isEmpty()
|| usbDevicePrefs.equals(usbDevice.getDeviceName()))) {
connectToUsbDevice(usbDevice);
} else {
findAttachedUsbDevice();
}
}
}
connectToBluetoothDevice();
return START_STICKY;
}
示例10: connectToDevice
import android.hardware.usb.UsbManager; //导入方法依赖的package包/类
private void connectToDevice(UsbManager manager, int vendorId,
int productId) throws DataSourceResourceException {
UsbDevice device = findDevice(manager, vendorId, productId);
if(manager.hasPermission(device)) {
Log.d(TAG, "Already have permission to use " + device);
openConnection(device);
} else {
Log.d(TAG, "Requesting permission for " + device);
manager.requestPermission(device, mPermissionIntent);
}
}
示例11: hasUsbPermission
import android.hardware.usb.UsbManager; //导入方法依赖的package包/类
private boolean hasUsbPermission() {
UsbManager usbManager = (UsbManager) this.getSystemService(Context.USB_SERVICE);
UsbDevice cnlDevice = UsbHidDriver.getUsbDevice(usbManager, MedtronicCnlIntentService.USB_VID, MedtronicCnlIntentService.USB_PID);
return !(usbManager != null && cnlDevice != null && !usbManager.hasPermission(cnlDevice));
}
示例12: updateDeviceInfo
import android.hardware.usb.UsbManager; //导入方法依赖的package包/类
/**
* ベンダー名・製品名・バージョン・シリアルを取得する
* @param manager
* @param device
* @param _info
* @return
*/
public static UsbDeviceInfo updateDeviceInfo(final UsbManager manager, final UsbDevice device, final UsbDeviceInfo _info) {
final UsbDeviceInfo info = _info != null ? _info : new UsbDeviceInfo();
info.clear();
if (device != null) {
if (BuildCheck.isLollipop()) {
info.manufacturer = device.getManufacturerName();
info.product = device.getProductName();
info.serial = device.getSerialNumber();
}
if (BuildCheck.isMarshmallow()) {
info.usb_version = device.getVersion();
}
if ((manager != null) && manager.hasPermission(device)) {
final UsbDeviceConnection connection = manager.openDevice(device);
final byte[] desc = connection.getRawDescriptors();
if (TextUtils.isEmpty(info.usb_version)) {
info.usb_version = String.format("%x.%02x", ((int)desc[3] & 0xff), ((int)desc[2] & 0xff));
}
if (TextUtils.isEmpty(info.version)) {
info.version = String.format("%x.%02x", ((int)desc[13] & 0xff), ((int)desc[12] & 0xff));
}
if (TextUtils.isEmpty(info.serial)) {
info.serial = connection.getSerial();
}
final byte[] languages = new byte[256];
int languageCount = 0;
// controlTransfer(int requestType, int request, int value, int index, byte[] buffer, int length, int timeout)
try {
int result = connection.controlTransfer(
USB_REQ_STANDARD_DEVICE_GET, // USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE
USB_REQ_GET_DESCRIPTOR,
(USB_DT_STRING << 8) | 0, 0, languages, 256, 0);
if (result > 0) {
languageCount = (result - 2) / 2;
}
if (languageCount > 0) {
if (TextUtils.isEmpty(info.manufacturer)) {
info.manufacturer = getString(connection, desc[14], languageCount, languages);
}
if (TextUtils.isEmpty(info.product)) {
info.product = getString(connection, desc[15], languageCount, languages);
}
if (TextUtils.isEmpty(info.serial)) {
info.serial = getString(connection, desc[16], languageCount, languages);
}
}
} finally {
connection.close();
}
}
if (TextUtils.isEmpty(info.manufacturer)) {
info.manufacturer = USBVendorId.vendorName(device.getVendorId());
}
if (TextUtils.isEmpty(info.manufacturer)) {
info.manufacturer = String.format("%04x", device.getVendorId());
}
if (TextUtils.isEmpty(info.product)) {
info.product = String.format("%04x", device.getProductId());
}
}
return info;
}
示例13: run
import android.hardware.usb.UsbManager; //导入方法依赖的package包/类
public void run() {
Log.d(TAG, "run readAndUpload");
try {
UsbManager usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
boolean hasPermission = faking;
for (final UsbDevice usbDevice : usbManager.getDeviceList()
.values()) {
if (usbManager.hasPermission(usbDevice)) {
hasPermission = true;
}
}
if (!hasPermission) {
synchronized (checkSerialLock) {
Log.d(TAG, "I have lost usb permission changing listener attached to false...");
listenerAttached = false;
mSerial.clearReadListener();
mHandlerRead.removeCallbacks(readByListener);
sendMessageDisconnectedToUI();
if (!mHandlerActive || isDestroying){
Log.d(TAG,"destroy readAnd Upload "+ mHandlerActive + " isDes "+ isDestroying);
return;
}
mHandlerCheckSerial.removeCallbacks(readAndUpload);
mHandlerCheckSerial.postDelayed(readAndUpload, MedtronicConstants.FIVE_SECONDS__MS);
return;
}
} else
sendMessageConnectedToUI();
boolean connected;
synchronized (mSerialLock) {
connected = isConnected();
}
if (connected) {
if (!isOnline())
sendErrorMessageToUI("NET connection error");
if (!listenerAttached) {
Log.d(TAG, "!listener attached readByListener triggered");
mSerial.clearReadListener();
mHandlerRead.removeCallbacks(readByListener);
mSerial.addReadListener(readListener);
mHandlerRead.post(readByListener);
listenerAttached = true;
}
} else {
openUsbSerial(false);
connected = isConnected();
if (!connected)
sendErrorMessageToUI("Receptor connection error");
else if (!isOnline())
sendErrorMessageToUI("Not online/connection error");
else {
sendMessageConnectedToUI();
sendMessageToUI("connected");
}
}
} catch (Exception e) {
sendExceptionToUI("Unable to read from receptor or upload", e);
}
synchronized (checkSerialLock) {
if (!mHandlerActive || isDestroying){
Log.d(TAG,"destroy readAnd Upload2 "+ mHandlerActive + " isDes "+ isDestroying);
return;
}
mHandlerCheckSerial.removeCallbacks(readAndUpload);
mHandlerCheckSerial.postDelayed(readAndUpload, MedtronicConstants.FIVE_SECONDS__MS);
}
}