Android Question device_filter.xml doesn't works

coslad

Well-Known Member
Licensed User
Longtime User
Hi
i need your help , i have a project where and android box tv (android 6) is connected through a usb-rs485 interface ( cp2104) with an energy monitor ,like this : (but without raspberry plus android tv box)

fetch.php


Every thing works well but my problem is that even though i have added the device into the device_filter.xml file , it asks me the permission to use it .

at the comand :

B4X:
Log("USBDeviceNr. " & z & " --- UsbPid = " & manager.GetDevices(z).ProductId & " vendor  " & manager.GetDevices(z).VendorId )

the answare is :
USBDeviceNr. 0 --- UsbPid = 60000 vendor 4292

the device_filter.xml is (there are even other 2 usb devices connected):

B4X:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<usb-device vendor-id="1921" product-id="21891"/>
<usb-device vendor-id="3468" product-id="316"/>
<usb-device vendor-id="4292" product-id="60000"/>
</resources>

the manifest file is :

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="5" android:targetSdkVersion="19"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
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>
)
AddReceiverText(USBService,
<intent-filter>
    <action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" />
</intent-filter>
)
'End of default text.

i can't understand .

The project is attached
 

Attachments

  • rs485.zip
    72.2 KB · Views: 386

MarcoRome

Expert
Licensed User
Longtime User
Hi
i need your help , i have a project where and android box tv (android 6) is connected through a usb-rs485 interface ( cp2104) with an energy monitor ,like this : (but without raspberry plus android tv box)

fetch.php


Every thing works well but my problem is that even though i have added the device into the device_filter.xml file , it asks me the permission to use it .

at the comand :

B4X:
Log("USBDeviceNr. " & z & " --- UsbPid = " & manager.GetDevices(z).ProductId & " vendor  " & manager.GetDevices(z).VendorId )

the answare is :
USBDeviceNr. 0 --- UsbPid = 60000 vendor 4292

the device_filter.xml is (there are even other 2 usb devices connected):

B4X:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<usb-device vendor-id="1921" product-id="21891"/>
<usb-device vendor-id="3468" product-id="316"/>
<usb-device vendor-id="4292" product-id="60000"/>
</resources>

the manifest file is :

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="5" android:targetSdkVersion="19"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
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>
)
AddReceiverText(USBService,
<intent-filter>
    <action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" />
</intent-filter>
)
'End of default text.

i can't understand .

The project is attached

Try, all in manifest in this way:
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="5" android:targetSdkVersion="19"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
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>
)
AddReceiverText(USBService,
<intent-filter>
    <action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" />
</intent-filter>
)
SetActivityAttribute(main, android:device_filter, @style/CustomActTheme)
CreateResource(values, device_filter.xml,
<?xml version="1.0" encoding="utf-8"?>
<resources>
<usb-device vendor-id="1921" product-id="21891"/>
<usb-device vendor-id="3468" product-id="316"/>
<usb-device vendor-id="4292" product-id="60000"/>
</resources>
)
 
Last edited:
Upvote 0

coslad

Well-Known Member
Licensed User
Longtime User
@Marco : thanks Marco, today I'll try.

@Erel: yes, it appears a checkbox , I made other application with b4a and b4r always trough a USB connection and always using device_filter file I solved, but in this case no!
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
@Marco : thanks Marco, today I'll try.

@Erel: yes, it appears a checkbox , I made other application with b4a and b4r always trough a USB connection and always using device_filter file I solved, but in this case no!
Quello che dice Erel e se hai dato l'ok delle Grant in modo "definitivo"

upload_2017-4-9_10-27-39.png
 
Upvote 0

coslad

Well-Known Member
Licensed User
Longtime User
Quello che dice Erel e se hai dato l'ok delle Grant in modo "definitivo"

View attachment 54615

Purtroppo no , ogni volta che il sistema si riavvia viene proposto il messaggio , il dispositivo funziona come un server e non è presidiato.

Unfortunately no, whenever the system reboots is proposed the message, the device operates as a server and is not manned.
 
Upvote 0

coslad

Well-Known Member
Licensed User
Longtime User
I even tried to install the app on a smartphone maybe can be a bug into the android tv box software, but it is the same .

If i attach then usb converter to the phone (or android tv) it cames up a message this message :

2l9hym1.jpg



it means that the usb is correctly associated to the app .

When i start the app it cames up this message :

14cfipg.jpg
 
Upvote 0

coslad

Well-Known Member
Licensed User
Longtime User
Yes Marco, if i check that checkbox, it works fine but what happen if the default setting come deleted ?
Without user the application will hang
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Will erase the parameters (in the settings), or (easier for the user) uninstall and reinstall the app
 
Upvote 0

coslad

Well-Known Member
Licensed User
Longtime User
I'm making some test , i let you know.
Thanks

Faccio delle prove e ti faccio sapere.
Grazie
 
Upvote 0
Top