Android Question USB serial request permission dialog

Sergio83

Active Member
Licensed User
Longtime User
Hello,

I'm building a home automation server based on an Android box. This box is connected to a micro-processeur via a serial link to serve some specific functions.

I would like to have a full automated start procedure of the server, particulaly regarding the request permission dialog for the usb serial device.

I done the following:

-1- adding the following lines to the xml manifest:

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" />)

-2- creating a device_filter.xml in the res folder, its containt is

<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- 0x0403 / 0x6001: FTDI FT232R UART -->
<usb-device vendor-id="1027" product-id="24577" />

<!-- 0x2341 / Arduino -->
<usb-device vendor-id="9025" />

<!-- 0x16C0 / 0x0483: Teensyduino -->
<usb-device vendor-id="5824" product-id="1155" />

<!-- 0x07D2 / 0x067B: PL2303 -->
<usb-device vendor-id="2002" product-id="1659" />

</resources>

At first start of my server I get the permission dialog box and I checked the default parameter option in the dialog box

After that everything is ok even if I restart my application there is no more dialog box.

But this will not allow to have a full automated start of my server (box and app)

What can I do to start my server whitout having the request permission dialog box?

Thanks by advance for you help (I know this question has already been asked ...)

Sorry for my english, that's my mother language ...
 

Sergio83

Active Member
Licensed User
Longtime User
Not sure that I understand. Do you see the permission dialog again at some point?

Hello Erel

Thank you to take care of my problem.

To sum up after booting my Android box the first time my server app starts I get the message permission box and I check the default parameter box, and then after I never get this message box again whatever I do.

If there is no turn around for that, it means that the start procedure of my server app at boot time can not be automated, for example when the Android box shutdown and restart after a loss a power.

Just to tell you about home automation server functionnalities:

- based on Android box my
- managing external devices via MQTT (I have a Mosquitto server apart based on OpenWRTan ):
 
Upvote 0

Sergio83

Active Member
Licensed User
Longtime User
Sorry but I still don't understand.

Why is it a problem that you never see the dialog again?

Hello Erel,

I'm sorry if my explanations are not so clear as they should be, but english is not my mother language ...

My problem is in deed to see the dialog box when I start my app server after booting my Android box.

What I want is just to never see the dialog box even after booting my Adnroid box, for a full automated start of my app server.

Hopping my explanations are clearer.

Regards
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I guess he need to use Api 22- to not get any permission dialog (which the use must accept once)
It is not related to the runtime permissions feature. The USB dialog is a special dialog.

The default behavior of this dialog is that if the user checks the "use by default ..." option then the dialog will never appear again until the app is uninstalled.

Make sure to NOT call UsbManager.RequestPermission. The dialog should appear automatically, once, when the USB is plugged in.
 
Upvote 0

Sergio83

Active Member
Licensed User
Longtime User
Hello Erel,

I'm using USBSerial 2.40 library, there's no UsbManager.RequestPermission" available, the equivalent is "ubsx.RequestPermission(1)" where "usbx" is an usbserial object instance.

To be more simple in testing I used the usbserial demo app joined with the library and I'm facing the same issue:

Once the app is installed, at start I get the permission dialog box, and then every time I stop and start this app demo I don't get anymore this message box.

But when I shutdown down my box and power on it again, at start of the app demo the dialog box appears again.

I think you understand this is not usable for a an app which should run whitout any human intervention.

Is there any way to use a usb to serial device connected to an Android device with a B4A app in a fully automated way?

I join the app demo and the library as it is delivered by the library author if that can help.

Thanks again for your help

regards
 

Attachments

  • USB_Serial_2.4.zip
    100.1 KB · Views: 403
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Is there any way to use a usb to serial device connected to an Android device with a B4A app in a fully automated way?
Anything that can be done in Java can also be done in B4A.

Start with reading this: https://developer.android.com/guide/topics/connectivity/usb/host.html#permission-d

You don't need to call RequestPermission. You need to run your app and then connect the USB cable. It should show the dialog and it should then remember the choice.
If it doesn't remember then it is a problem specific to your device or Android version.
There are known issues with this feature:
https://code.google.com/p/android/issues/detail?id=178062
 
Upvote 0

Sergio83

Active Member
Licensed User
Longtime User
OK Erel,

When you say :

Anything that can be done in Java can also be done in B4A.

Of course I trust you!

Where I probably mistaken is that Android is phone and tablet oriented with no care regarding human intervention to run an application, and certainly not server application oriented.

Sorry to have bother you a so long time, I will change my mind and go back to my first idea which is:

- having my client apps running on my Android phones and tablets with B4A, instead of HTML interface

- having my servers app (CCTV, Home automation, ...) still running on my OpenWRT platforms

- having my Mosquitto broker running on OpenWRT platform

- having my home devices (convertor heater, garden watering system, light, smoke sensors, PIR sensors, fire sensors, temperature sensors, and so on), managed with ESP8266 platforms running NodeMCU with Lua embeded and MQTT client.

You can consider that this thread is closed.

Thank you again for your help.

And ... continue to improve your B4A project for the benefit of all of us.

Regards
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…