Android Question In term of USB device Permision

Alhootti

Active Member
im using
felUsbSerial & UsbManager lib
each time i reboot my device it request Permission again.
despite i used in device filter.xml:
B4X:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- 0x10c4 / 0x800a GNSS RECIEVER -->
    <usb-device vendor-id="0x1546" product-id="0x01a8"/>
</resources>

also this:
B4X:
usbserial.Initialize2("serial", device, -1, "CDCSerialDevice")
B4X:
AddActivityText(main, <intent-filter>
    <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
    <meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
        android:resource="@xml/device_filter" />)
I should select permission once then no need for permission even after reboot
How i can solve this issue?
 

Alhootti

Active Member
but if i unplug the USB then plug it again it work after reboot perfectly.
the issue is when i launch the app after reboot
 
Upvote 0

Alhootti

Active Member
im getting this Error :
B4X:
Compiling resources    Error
res\values\device_filter.xml:3: error: unknown resource type 'usb-device'.
res\values\device_filter.xml: error: file failed to compile.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
my understanding is that the device-id and vendor-id are to be decimal, not hex.
 
Upvote 0

Alhootti

Active Member
VID & PID
 

Attachments

  • VID.jpeg
    VID.jpeg
    315.5 KB · Views: 39
Upvote 0

Alhootti

Active Member
im using this code :
B4X:
If manager.GetDevices.Length = 0 Then
        ToastMessageShow(" No Device ", True)
    Else
        Dim device As UsbDevice = manager.GetDevices(0) 'assuming that there is exactly one
'        Dim VendorId As Int = device.VendorId
'        Dim ProductId As Int = device.ProductId
'        VendorId = 0x1546
'        ProductId = 0x01a8
        If manager.HasPermission(device) = False Then
            ToastMessageShow("Please allow connection and click again.", True)
            manager.RequestPermission(device)
            Else If manager.HasPermission(device) = True Then
'                usbserial.Initialize("serial", device, -1)
                usbserial.Initialize2("serial", device, -1, "CDCSerialDevice")
                usbserial.BaudRate = 115200
                usbserial.DataBits = usbserial.DATA_BITS_8
                usbserial.StartReading
                ToastMessageShow("Done  ", True)
            End If
            End If

in Manifest :
B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="34"/>
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.USB_PERMISSION" />
<uses-feature android:name="android.hardware.usb.host" />
<uses-feature android:name="android.hardware.usb.accessory"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.LightTheme)
'End of default text.
CreateResource(xml, device_filter.xml,
<resources>
<usb-device vendor-id="0x1546" product-id="0x01a8"/>
</resources>
)
AddActivityText(main, <intent-filter>
    <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
    <meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
        android:resource="@xml/device_filter" />)

I don't know where is the wrong !!!
 
Last edited:
Upvote 0

Alhootti

Active Member
actually in case if i unplug it then plug it , it work without requesting any permission after reboot.
just the issue tack place when i launch the app after reboot directly.
 
Upvote 0
Top