當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。