当前位置: 首页>>代码示例>>Java>>正文


Java UsbManager.hasPermission方法代码示例

本文整理汇总了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;
}
 
开发者ID:rostskadat,项目名称:OTGDiskBackup,代码行数:26,代码来源:MountTask.java

示例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);
        }
    }
}
 
开发者ID:iyundong,项目名称:InstantUpload,代码行数:21,代码来源:ControllerActivity.java

示例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);
            }
        }

    }
 
开发者ID:victordiaz,项目名称:phonk,代码行数:21,代码来源:AdkPort.java

示例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");
    }
}
 
开发者ID:dji-sdk,项目名称:Android-Bridge-App,代码行数:23,代码来源:USBConnectionManager.java

示例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);
    }
}
 
开发者ID:mapaiva,项目名称:react-native-usbserial,代码行数:21,代码来源:ReactUsbSerialModule.java

示例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());
        }
	}
 
开发者ID:jiaminghan,项目名称:droidplanner-master,代码行数:26,代码来源:UsbCDCConnection.java

示例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);
	}
}
 
开发者ID:Neofect,项目名称:Communicator,代码行数:25,代码来源:UsbConnection.java

示例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));
    }
}
 
开发者ID:martinmarinov,项目名称:AndroidDvbDriver,代码行数:12,代码来源:UsbPermissionObtainer.java

示例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;
}
 
开发者ID:delletenebre,项目名称:SerialManager,代码行数:29,代码来源:ConnectionService.java

示例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);
    }
}
 
开发者ID:bibhrajit,项目名称:openxc-androidStudio,代码行数:12,代码来源:UsbVehicleInterface.java

示例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));
}
 
开发者ID:pazaan,项目名称:600SeriesAndroidUploader,代码行数:7,代码来源:MainActivity.java

示例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;
}
 
开发者ID:DeviceConnect,项目名称:DeviceConnect-Android,代码行数:73,代码来源:USBMonitor.java

示例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);
	}
}
 
开发者ID:arbox0,项目名称:MedtronicUploader,代码行数:73,代码来源:MedtronicCGMService.java


注:本文中的android.hardware.usb.UsbManager.hasPermission方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。