Java Code Examples for com.serenegiant.utils.BuildCheck#isMarshmallow()
The following examples show how to use
com.serenegiant.utils.BuildCheck#isMarshmallow() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java From ScreenRecordingSample with Apache License 2.0 | 6 votes |
/** * Callback listener from MessageDialogFragmentV4 * @param dialog * @param requestCode * @param permissions * @param result */ @SuppressLint("NewApi") @Override public void onMessageDialogResult(final MessageDialogFragment dialog, final int requestCode, final String[] permissions, final boolean result) { if (result) { // request permission(s) when user touched/clicked OK if (BuildCheck.isMarshmallow()) { requestPermissions(permissions, requestCode); return; } } // check permission and call #checkPermissionResult when user canceled or not Android6(and later) for (final String permission: permissions) { checkPermissionResult(requestCode, permission, PermissionCheck.hasPermission(this, permission)); } }
Example 2
Source File: USBMonitor.java From AndroidUSBCamera with Apache License 2.0 | 5 votes |
/** * USB機器毎の設定保存用にデバイスキー名を生成する。この機器名をHashMapのキーにする * UsbDeviceがopenしている時のみ有効 * ベンダーID, プロダクトID, デバイスクラス, デバイスサブクラス, デバイスプロトコルから生成 * serialがnullや空文字でなければserialを含めたデバイスキー名を生成する * useNewAPI=trueでAPIレベルを満たしていればマニュファクチャ名, バージョン, コンフィギュレーションカウントも使う * @param device nullなら空文字列を返す * @param serial UsbDeviceConnection#getSerialで取得したシリアル番号を渡す, nullでuseNewAPI=trueでAPI>=21なら内部で取得 * @param useNewAPI API>=21またはAPI>=23のみで使用可能なメソッドも使用する(ただし機器によってはnullが返ってくるので有効かどうかは機器による) * @return */ @SuppressLint("NewApi") public static final String getDeviceKeyName(final UsbDevice device, final String serial, final boolean useNewAPI) { if (device == null) return ""; final StringBuilder sb = new StringBuilder(); sb.append(device.getVendorId()); sb.append("#"); // API >= 12 sb.append(device.getProductId()); sb.append("#"); // API >= 12 sb.append(device.getDeviceClass()); sb.append("#"); // API >= 12 sb.append(device.getDeviceSubclass()); sb.append("#"); // API >= 12 sb.append(device.getDeviceProtocol()); // API >= 12 if (!TextUtils.isEmpty(serial)) { sb.append("#"); sb.append(serial); } if (useNewAPI && BuildCheck.isAndroid5()) { sb.append("#"); if (TextUtils.isEmpty(serial)) { sb.append(device.getSerialNumber()); sb.append("#"); // API >= 21 } sb.append(device.getManufacturerName()); sb.append("#"); // API >= 21 sb.append(device.getConfigurationCount()); sb.append("#"); // API >= 21 if (BuildCheck.isMarshmallow()) { sb.append(device.getVersion()); sb.append("#"); // API >= 23 } } // if (DEBUG) Log.v(TAG, "getDeviceKeyName:" + sb.toString()); return sb.toString(); }
Example 3
Source File: USBMonitor.java From DeviceConnect-Android with MIT License | 5 votes |
/** * USB機器毎の設定保存用にデバイスキー名を生成する。この機器名をHashMapのキーにする * UsbDeviceがopenしている時のみ有効 * ベンダーID, プロダクトID, デバイスクラス, デバイスサブクラス, デバイスプロトコルから生成 * serialがnullや空文字でなければserialを含めたデバイスキー名を生成する * useNewAPI=trueでAPIレベルを満たしていればマニュファクチャ名, バージョン, コンフィギュレーションカウントも使う * @param device nullなら空文字列を返す * @param serial UsbDeviceConnection#getSerialで取得したシリアル番号を渡す, nullでuseNewAPI=trueでAPI>=21なら内部で取得 * @param useNewAPI API>=21またはAPI>=23のみで使用可能なメソッドも使用する(ただし機器によってはnullが返ってくるので有効かどうかは機器による) * @return */ @SuppressLint("NewApi") public static final String getDeviceKeyName(final UsbDevice device, final String serial, final boolean useNewAPI) throws SecurityException { if (device == null) return ""; final StringBuilder sb = new StringBuilder(); sb.append(device.getVendorId()); sb.append("#"); // API >= 12 sb.append(device.getProductId()); sb.append("#"); // API >= 12 sb.append(device.getDeviceClass()); sb.append("#"); // API >= 12 sb.append(device.getDeviceSubclass()); sb.append("#"); // API >= 12 sb.append(device.getDeviceProtocol()); // API >= 12 if (!TextUtils.isEmpty(serial)) { sb.append("#"); sb.append(serial); } if (useNewAPI && BuildCheck.isAndroid5()) { sb.append("#"); if (TextUtils.isEmpty(serial)) { sb.append(device.getSerialNumber()); sb.append("#"); // API >= 21 } sb.append(device.getManufacturerName()); sb.append("#"); // API >= 21 sb.append(device.getConfigurationCount()); sb.append("#"); // API >= 21 if (BuildCheck.isMarshmallow()) { sb.append(device.getVersion()); sb.append("#"); // API >= 23 } } // if (DEBUG) Log.v(TAG, "getDeviceKeyName:" + sb.toString()); return sb.toString(); }
Example 4
Source File: USBMonitor.java From AndroidUSBCamera with Apache License 2.0 | 4 votes |
/** * ベンダー名・製品名・バージョン・シリアルを取得する * @param manager * @param device * @param _info * @return */ @TargetApi(Build.VERSION_CODES.M) 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); if(connection == null) { return null; } 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; }
Example 5
Source File: USBMonitor.java From DeviceConnect-Android with MIT License | 4 votes |
/** * ベンダー名・製品名・バージョン・シリアルを取得する * @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; }