Android Question Autoloading an app and bring it up on the screen automatically upon boot up

rleiman

Well-Known Member
Licensed User
Longtime User
Greetings everyone,

We have the LineageOS KonstaKANG Android version 12 running on a Raspberry Pi and I developed a B4A app that displays a web site on the Raspberry Pi. The app works perfectly. It's kind of like a slide show that displays the web site and displays image files and cycles back to the web site. It's also the only other app developed in Android for the Raspberry Pi. We would like to have that app auto load and open up to display on the screen automatically but don't know how to get that part working. Can you tell us what additional coding would be needed for the app or point us to a link that has the coding that will do that?

Thanks.
 

rleiman

Well-Known Member
Licensed User
Longtime User
An app need to hold the special "draw on top of other apps" permission in order to start an activity from the background: https://www.b4x.com/android/forum/threads/draw-on-top-of-other-apps-permission.90513/#content
Thanks for the link. I added the procedures from that post into the app.

The project also now has the phone and JavaObject library and I added the permission into the manifest editor. Which library am I missing for the new coding?

Screenshot 2022-04-03 at 04.35.58.png
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Thanks for the link. I added the procedures from that post into the app.
You can put this code in a class to check whether your app has permission and open the settings page if needed
Use this code, put it into a class named RequestDrawOverPermission like described.
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
Use this code, put it into a class named RequestDrawOverPermission like described.
Getting closer.

Thanks for the reply. After creating a standard class module and moving the new coding over there I could compile and run the app. When I ran the app, it was taken to a list of apps where I can give the permission but my app was not in the list. I had already added SYSTEM_ALERT_WINDOW into the manifest editor based on the linked post. After looking at the coding from the post, I took a guess I also needed MANAGE_OVERLAY_PERMISSION in there as well. When I ran the app again my app was there in the list to turn on the permission.

The manifest editor now has these 2 new lines.
B4X:
AddPermission(android.permission.SYSTEM_ALERT_WINDOW)
AddPermission(android.permission.MANAGE_OVERLAY_PERMISSION)

I have several log statements in the app and noticed the service module that I use to start to make the app screen display has this coding in the Service_Start procedure:
B4X:
Sub Service_Start (StartingIntent As Intent)
    Service.StopAutomaticForeground 'Call this when the background task completes (if there is one)
    Log("About to call setup procedure.")
    CallSub(Main, "Setup")
End Sub

I'm also using #StartAtBoot: true so the service module is loading up which I can see in the logs.

In the B4XMainPage I have this coding:
B4X:
public Sub Setup
 
    Log("At Setup procedure.")
    Root.LoadLayout("MainPage")
 
    WebViewABRICC.LoadUrl("https://mawaqit.net/en/abricc-acton-01720-united-states")
    WebViewABRICC.Height = Root.Height
    WebViewABRICC.Width = Root.Width
 
    ImageViewABRICC.Height = Root.Height
    ImageViewABRICC.Width = Root.Width
End Sub

The Log("At Setup procedure.") statement is not executed when I restart my test development phone. If I just start the app by tapping the app icon, then that log statement is executed. I also do know that the service module is starting because the Log("About to call setup procedure.") statement executes, but not the Setup procedure in B4XMainPage. Is there a Wait For I can use to wait until B4XMainPage actually starts before calling the Setup procedure?

Since this app is not large, I can post all of the code if that helps.
 

Attachments

  • Screenshot 2022-04-03 at 11.03.41.png
    Screenshot 2022-04-03 at 11.03.41.png
    276.9 KB · Views: 111
Last edited:
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
I'm uploading the project if anyone has some time to look at it.

Thanks.
 

Attachments

  • Project.zip
    413.2 KB · Views: 125
Upvote 0
Top