public void requestPermission(final int deviceId) {
/* Request permission with the USB manager. */
final UsbDevice device = findDevice(deviceId);
if (device != null) {
NativeLogger.log("Requesting permission for device: " + device.getDeviceName());
/* Create intent and request permission with the USB manager. */
final UsbManager manager = (UsbManager) this.m_context.getSystemService(Context.USB_SERVICE);
if (manager == null) {
NativeLogger.log("UsbManager is null. Cannot request permission.");
return;
}
final Intent intent = new Intent(ACTION_USB_PERMISSION);
final PendingIntent permissionIntent;
if (Build.VERSION.SDK_INT >= 23) {
// Create a PendingIntent using FLAG_IMMUTABLE.
permissionIntent = PendingIntent.getBroadcast(this.m_context, 0, intent,
PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE);
} else {
// Existing code that creates a PendingIntent.
permissionIntent = PendingIntent.getBroadcast(this.m_context, 0, intent, PendingIntent.FLAG_IMMUTABLE);
}
NativeLogger.log("PendingIntent created for USB permission: " + intent.getAction());
manager.requestPermission(device, permissionIntent);
} else {
NativeLogger.log("Device not found for deviceId: " + deviceId);
}
}
Это нативное приложение. Я пытаюсь создать мостовой модуль, не уверен, что делаю неправильно, что-нибудь поможет. спасибо
у меня простая настройка [code]private final BroadcastReceiver m_usbReceiver = new BroadcastReceiver() { @Override public void onReceive(final Context context, final Intent intent) { try { final IBScan ibScan = IBScan.m_instance; final String action = intent.getAction();
ibScan.getDeviceCount();
/* Receive event about device attachment. */ if (action.equals(UsbManager.ACTION_USB_DEVICE_ATTACHED)) { NativeLogger.log("ACTION_USB_DEVICE_ATTACHED"); UsbDevice device = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE); if (device != null) { final boolean isScanDevice = isScanDevice(device); if (isScanDevice) { callbackScanDeviceAttached(device.getDeviceId()); } } }
/* Receive event about device detachment. */ else if (action.equals(UsbManager.ACTION_USB_DEVICE_DETACHED)) { NativeLogger.log("ACTION_USB_DEVICE_DETACHED"); UsbDevice device = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE); if (device != null) { final boolean isScanDevice = isScanDevice(device); if (isScanDevice) { callbackScanDeviceDetached(device.getDeviceId()); } } }
/* Receive event about access permission granted or denied. */ else if (action.equals(ACTION_USB_PERMISSION)) { NativeLogger.log("ACTION_USB_PERMISSION received."); final boolean exists = intent.hasExtra(UsbManager.EXTRA_PERMISSION_GRANTED); // always false NativeLogger.log("EXTRA_PERMISSION_GRANTED exists: " + exists);
if (exists) { final boolean granted = intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false); NativeLogger.log("Permission granted: " + granted);
final UsbDevice device = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE); if (device != null) { NativeLogger.log("Device found: " + device.getDeviceName()); if (isScanDevice(device)) { NativeLogger.log("Device is a scan device."); callbackScanDevicePermissionGranted(device.getDeviceId(), granted); } else { NativeLogger.log("Device is not a scan device."); } } else { NativeLogger.log("Device is null in intent."); } } else { NativeLogger.log("EXTRA_PERMISSION_GRANTED key is missing. Retrying..."); } } } catch (IBScanException ibse) { ibse.printStackTrace(); } } }; [/code] И вот как я запрашиваю разрешения: [code]public void requestPermission(final int deviceId) { /* Request permission with the USB manager. */ final UsbDevice device = findDevice(deviceId); if (device != null) { NativeLogger.log("Requesting permission for device: " + device.getDeviceName());
/* Create intent and request permission with the USB manager. */ final UsbManager manager = (UsbManager) this.m_context.getSystemService(Context.USB_SERVICE);
if (manager == null) { NativeLogger.log("UsbManager is null. Cannot request permission."); return; }
final Intent intent = new Intent(ACTION_USB_PERMISSION); final PendingIntent permissionIntent;
if (Build.VERSION.SDK_INT >= 23) { // Create a PendingIntent using FLAG_IMMUTABLE. permissionIntent = PendingIntent.getBroadcast(this.m_context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE); } else { // Existing code that creates a PendingIntent. permissionIntent = PendingIntent.getBroadcast(this.m_context, 0, intent, PendingIntent.FLAG_IMMUTABLE); }
NativeLogger.log("PendingIntent created for USB permission: " + intent.getAction()); manager.requestPermission(device, permissionIntent); } else { NativeLogger.log("Device not found for deviceId: " + deviceId); } } [/code] Это нативное приложение. Я пытаюсь создать мостовой модуль, не уверен, что делаю неправильно, что-нибудь поможет. спасибо
Вам нужно использовать явное намерение.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
Intent intent = new Intent(ACTION_USB_PERMISSION);
intent.setPackage(mContext.getPackageName());
mPermissionIntent = PendingIntent.getBroadcast(mContext,...
Не вдаваясь в подробности (соглашение о неразглашении), наше приложение (kotlin + compose) позволяет пользователям получать звонки, которые они могут принять или отклонить в уведомлениях. Когда экран заблокирован и поступает вызов, отображается...
Я устраняю проблему, связанную с USB, из-за обновления до SDK34 и сбоя в Android 14. У меня нет физического устройства, поэтому я прибегаю к эмулятору.
Я изменил USB-модуль устройство: такое, чтобы устройство было доступно для чтения/записи с...
Я использую , чтобы показать всплывающее окно, которое накладывается на другие приложения, но Android 12 блокирует касания. Согласно документации, он блокирует события касания. как я могу разрешить касания на Android 12?
Учитывая мой исходный код, я пытаюсь получить широту и долготу после включения GPS, но получаю ошибку, сбой FusedLocationProvider, почему это происходит, я не понимаю, и получаю эту ошибку. uid 10613 не имеет ни одного из .