Hi, I'm trying to write an application that starts based on intent-filter related to an USB to serial converter.
I'm trying to execute it on an industrial panel with Android 7.1.2
Everything is working fine, the app is starting when the USB cable is connected, on the first run is asking for permission and if the checkbox is checked, it "remembers" the permission after boot.
The only problem I'm facing here is on boot. The app is starting, but the layout is not loaded and stales. I was trying to pus some spy messages and even create a file in Activity_Create,
in the first line. The file is not created. I have root access and I can check with adb. If I'm inserting the USB cable after boot and launcher is shown, everything works.
It keep the permissions, everything is fine. But if I'm booting with the connected cable, then it's stalled. Even this simple application below fails. It shows the application title, but not moving forward, loading the activity layout. If I'm pressing back button on navigation bar, the application closes, the boot sequence continues with launcher loading. Disconnecting and reconnecting the USB cable after that, is triggering the app and everything works.
Here is the minimum app I'm testing with:
Also, my manifest file si the following:
And, to be more interesting, checking for active tasks, sometimes (not every time) I found 2 (like in the picture). If I'm selecting one of them, the application runs correctly. Also, when only one is available, if I'm selecting that, it is not working.
If, then, I'm switching to the other one, it is also run correctly.
I'm stuck here for the moment, I though I've made some mistakes in the main app, which is way bigger, that is why I've created the above one, for testing basic behavior, just to find that it's misbehaving in the same way.
Any hint will be highly appreciated, since the app should be able to work in an unattended environment and runtime permissions for UsbManager are not persistent, the only persistence is working by using intent-filter in the manifest, but with the above described issue.
I'm trying to execute it on an industrial panel with Android 7.1.2
Everything is working fine, the app is starting when the USB cable is connected, on the first run is asking for permission and if the checkbox is checked, it "remembers" the permission after boot.
The only problem I'm facing here is on boot. The app is starting, but the layout is not loaded and stales. I was trying to pus some spy messages and even create a file in Activity_Create,
in the first line. The file is not created. I have root access and I can check with adb. If I'm inserting the USB cable after boot and launcher is shown, everything works.
It keep the permissions, everything is fine. But if I'm booting with the connected cable, then it's stalled. Even this simple application below fails. It shows the application title, but not moving forward, loading the activity layout. If I'm pressing back button on navigation bar, the application closes, the boot sequence continues with launcher loading. Disconnecting and reconnecting the USB cable after that, is triggering the app and everything works.
Here is the minimum app I'm testing with:
Application example:
#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private xui As XUI
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
End Sub
Sub Activity_Create(FirstTime As Boolean)
ToastMessageShow("create",True)
File.WriteString(File.DirInternal,DateTime.Now,DateTime.Now)
Activity.LoadLayout("Layout")
End Sub
Sub Activity_Resume
ToastMessageShow("Resume",True)
End Sub
Sub Activity_Pause (UserClosed As Boolean)
ToastMessageShow("Pause",True)
End Sub
Sub Button1_Click
xui.MsgboxAsync("Hello world!", "B4X")
End Sub
Also, my manifest file si the following:
manifest:
'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.
SetActivityAttribute(Main, android:directBootAware, "true")
SetActivityAttribute(Main, android:launchMode, "singleTask")
CreateResource(xml, device_filter.xml,
<resources>
<!-- Your device CH340G for PICOVEND EZ boards -->
<usb-device vendor-id="6790" product-id="29987"/>
</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" />
)
And, to be more interesting, checking for active tasks, sometimes (not every time) I found 2 (like in the picture). If I'm selecting one of them, the application runs correctly. Also, when only one is available, if I'm selecting that, it is not working.
If, then, I'm switching to the other one, it is also run correctly.
I'm stuck here for the moment, I though I've made some mistakes in the main app, which is way bigger, that is why I've created the above one, for testing basic behavior, just to find that it's misbehaving in the same way.
Any hint will be highly appreciated, since the app should be able to work in an unattended environment and runtime permissions for UsbManager are not persistent, the only persistence is working by using intent-filter in the manifest, but with the above described issue.