Android Question usb-device trouble

EduardoElias

Well-Known Member
Licensed User
Longtime User
Hi great people!

I am in trouble to make USB Device configuration. My app is using a USB pinpad for payments just fine.

Howeve EACH TIME that I turn on/off the device it ask for permission to use again. Giving the permission even clicking the checkbox does not change this behavior.

I tried adding the manifest code but now I am getting the following error:

B4X:
B4A Version: 10.60
Parsing code.    (0.01s)
    Java Version: 8
Building folders structure.    (0.20s)
Compiling code.    (0.12s)
Compiling layouts code.    (0.00s)
Organizing libraries.    (0.00s)
    (AndroidX SDK)
Generating R file.    (0.00s)
Compiling generated Java code.    (9.59s)
Convert byte code - dex.    (108.40s)
Packaging files.    Error
fakeLogOpen(/dev/log_crash) failed
fakeLogOpen(/dev/log_security) failed
fakeLogOpen(/dev/log_security) failed
fakeLogOpen(/dev/log_security) failed
res\values\device_filter.xml:3: error: Found tag usb-device where item is expected

AAPT path: C:\Android\tools\..\build-tools\27.0.1\aapt.exe
Exit code:1*** Legacy debugger is deprecated. ***
It is recommended to switch to the default debugger (Tools - IDE Options).

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="29"/>
<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.

AddManifestText(<uses-feature android:name="android.hardware.usb.accessory"/>)

CreateResource(values, device_filter.xml,
<resources>
<usb-device vendor-id="1753" product-id="c902"/>
</resources>
)

AddApplicationText(
<activity android:name="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" />
</activity>
)




device_filter.xml
B4X:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<usb-device vendor-id="1753" product-id="c902"/>
</resources>

what is wrong ?
 
Last edited:

EduardoElias

Well-Known Member
Licensed User
Longtime User
Have you added a file named device_filter.xml? Don't. The CreateResource command will create it for you.
I have not, I let it create it automatically... but even with that I still getting

"res\values\device_filter.xml:3: error: Found tag usb-device where item is expected"

only when I remove these manifest (creating the usb-device and resource) it is back working.

I need that the app does not keep asking for permission to use the USB everytime.
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
It should be
B4X:
CreateResource(xml, device_filter.xml,
<resources>
<usb-device vendor-id="1753" product-id="c902"/>
</resources>
)

instead of
B4X:
CreateResource(values, device_filter.xml,
<resources>
<usb-device vendor-id="1753" product-id="c902"/>
</resources>
)
 
Upvote 0

EduardoElias

Well-Known Member
Licensed User
Longtime User
It should be
B4X:
CreateResource(xml, device_filter.xml,
<resources>
<usb-device vendor-id="1753" product-id="c902"/>
</resources>
)

instead of
B4X:
CreateResource(values, device_filter.xml,
<resources>
<usb-device vendor-id="1753" product-id="c902"/>
</resources>
)
that was fixed ! many thanks !

however got this now: never saw before

B4X:
B4A Version: 10.60
Parsing code.    (0.10s)
    Java Version: 8
Building folders structure.    (0.03s)
Compiling code.    (0.13s)
Compiling layouts code.    (0.00s)
Organizing libraries.    (0.00s)
    (AndroidX SDK)
Generating R file.    Error
c:\android\tools\..\extras\b4a_remote\androidx\savedstate\savedstate\1.1.0\unpacked-savedstate-1.1.0\res\values\values.xml:3: error: Found tag id where item is expected
c:\android\tools\..\extras\b4a_remote\androidx\lifecycle\lifecycle-viewmodel\2.3.0\unpacked-lifecycle-viewmodel-2.3.0\res\values\values.xml:3: error: Found tag id where item is expected
c:\android\tools\..\extras\b4a_remote\androidx\lifecycle\lifecycle-runtime\2.3.0\unpacked-lifecycle-runtime-2.3.0\res\values\values.xml:3: error: Found tag id where item is expected
*** Legacy debugger is deprecated. ***
 It is recommended to switch to the default debugger (Tools - IDE Options).
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Possibly a copy of values.xml has been left in the 'values' folder, perhaps from previous compilations.

Try cleaning the project and/or uninstalling the current compilation from your device. Unless it is being generated somewhere else, it should disappear.
 
Upvote 0

EduardoElias

Well-Known Member
Licensed User
Longtime User
Possibly a copy of values.xml has been left in the 'values' folder, perhaps from previous compilations.

Try cleaning the project and/or uninstalling the current compilation from your device. Unless it is being generated somewhere else, it should disappear.

deleted those xml and now everything is working and compiling !!!!! very nice help thank you!
 
Upvote 0
Top