Android Question Runtime Requests-Auto handling

Joanne

Member
Licensed User
Is there any way that we will be able to automatically accept a system dialog asking us to either allow or deny a Runtime request on startup?

I am using the USB-port(OTG adapter) as a serial port and i would like the system dialog to always be accepted automatically. An alternative would be to show me how to do the permissions for this.
 

Attachments

  • uGridProblem.PNG
    uGridProblem.PNG
    19.9 KB · Views: 128

DonManfred

Expert
Licensed User
Longtime User
o always be accepted automatically
It is not possible. The device user must accept it based on Google Guidelines.

You, as the deviceuser, can check the Checkbox and then your app will be used always when the OTG device connects. You have to answer it only once then (hopefully). Point is that the device user MUST accept it.
 
Last edited:
Upvote 0

Joanne

Member
Licensed User
If you use Runtime Permissions (Runtime Permissions (Android 6.0+ Permissions)), the user will only be asked once (assuming they accept). After that your check of that permission will return true & the dialog won't be presented.

- Colin.

I am trying to make a automated unit where no one will be coming close to the device or even able to access it. And if i do check the box the next time it reboots the device will be asking me to allow the app to use the port
 
Upvote 0

Joanne

Member
Licensed User
It is not possible. The device user must accept it based on Google Guidelines.

You, as the deviceuser, can check the Checkbox and then your app will be used always when the OTG device connects. You have to answer it only once then.


Even after i have checked the tick box to set my app as a default the next time it boots the app again asks for a user to accept it
 
Upvote 0

Joanne

Member
Licensed User
Don't confuse runtime permissions with the USB permission dialog. They are not related.

You should use the XML based permission for USB. It will then only ask the permission once.

B4X:
[INDENT][INDENT]'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: [URL]https://www.b4x.com/forum/showthread.php?p=78136[/URL]
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="26"/>
<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.DarkTheme)
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
'End of default text.

AddManifestText(<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="23" />
)
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" />)

CreateResource(xml, device_filter.xml,
<resources>
<usb-device vendor-id="1027" product-id="24577" />
</resources>
)
[Code][/INDENT][/INDENT]
Hi Erel this is currently how my manifest looks, do you possibly have any ideas where i could be going wrong?
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Please use [code]code here...[/code] tags when posting code.

Not related but you should remove this:
B4X:
AddManifestText(<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="23" />
)

Looks correct. Make sure that there isn't any other app that might be registered with the same filter.
 
Upvote 0

Joanne

Member
Licensed User
Please use [code]code here...[/code] tags when posting code.

Not related but you should remove this:
B4X:
AddManifestText(<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="23" />
)

Looks correct. Make sure that there isn't any other app that might be registered with the same filter.

I only have the single app running on the android device. So i don't think that there is any apps that would use the same ports.

But thank you to everyone for very fast and helpful replies
 
Upvote 0

Joanne

Member
Licensed User
Im currently running it on a raspberry pi 3b+. I have tried to make it work on the pi a samsung tablet, a alcatel tablet and samsung phone. Unfortunatley all of them still ask the first time after a device startup. I am not to sure where i am going wrong.
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="26"/>
<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.DarkTheme)
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
'End of default text.

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

CreateResource(xml, device_filter.xml,
<resources>
<usb-device vendor-id="1027" product-id="24577" />
</resources>
)
[Code] 

[Code]
If (usb1.HasPermission(1)) Then    ' Ver_2.4
        Log(usb1.DeviceInfo(1))
        'This is very important - ( VendorId, ProductId )
        usb1.SetCustomDevice(usb1.DRIVER_FTDI, "1027","24577" )
       
       
        Dim dev As Int
        dev = usb1.Open(115200, 1)
        If dev <> usb1.USB_NONE Then
            Log("Connected successfully!!!! 1")
       
           
            astreams1.Initialize(usb1.GetInputStream, usb1.GetOutputStream, "astreams1")

            'This is important
            usb1.SetParameters(115200, usb1.DATABITS_8,usb1.STOPBITS_1, usb1.PARITY_NONE)
           
            'Here if you want code that call print
        Else
            Log("Error opening USB port 1!!!!!")
        End If
    Else
    usb1.RequestPermission(1)  ' Ver_2.4
End If
[Code]
 
Upvote 0
Top