Android Question Service 'Run_App' that not start secondary app when it is in background

amorosik

Expert
Licensed User
'Run_App' is a service write in B4A designed to be started automatically when the operating system is started and to wait for the receipt of sms
When the smartphone receives a text message, Run_App service reads the sms body, and if present the command START_PROG = com.peppe.app_1 starts the code to run the app whose package is com.peppe.app_1
Well, the program seems to work as intended but only if it is started manually and the focus is on the main form
If another app is launched and the focus switches to the latter, the Run_App program does not seem to work anymore
I inserted some log lines in it to understand if the sms is received, interpreted correctly, and the attempt to start com.peppe.app_1 is performed and in fact it is so, all the code seems to be executed correctly, but the app_1 program does not start

B4X:
Sub StartApp (command as string)
   Dim Pm1 as PackageManager
   StartActivity (Pm1.getApplicationIntent (command))
   end sub

Then recap the line StartActivity (Pm1.getApplicationIntent (command))
it is definitely performed but has no effect
This only if the Run_App program is in the background, while if it is in the foreground then everything works correctly

The question is: why does the
StartActivity(Pm1.getApplicationIntent (command))
not start the requested app?
 
Last edited:

amorosik

Expert
Licensed User
On newer versions of Android, regular apps cannot start activities while in the background.

The code above is inserted in a module of type 'service'
What do you mean by 'regular app'?
I think you mean an app with at least one screen (activity) visible, is that correct?
Besides 'regular apps' and 'service apps' what other types is available?

What type of app should I use, in the B4X environment and for Android 9 e 10, in order to have these features at the same time:
- start automatically when the operating system is started
- receive sms, push notification
- when receiving sms, push message, react starting other apps
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
What do you mean by 'regular app'?
any app which is not a systemapp.
I think you mean an app with at least one screen (activity) visible, is that correct?
A app in background is an app with no active visible Activities.

You are not able to read SMS unless your app is the Devices default Messanger App. At least on higher Androidversions.
 
Upvote 0

amorosik

Expert
Licensed User
any app which is not a systemapp.
A app in background is an app with no active visible Activities.
You are not able to read SMS unless your app is the Devices default Messanger App. At least on higher Androidversions.


Thanks for the reply
Actually, on Android 9 and 10, i receive correctly and read sms with the code available on example:
What I can't do is start a second app (only with primary app in foreground)
If in the received SMS body there is the package name of a second app, with the code

B4X:
Dim pm As PackageManager
StartActivity (pm.GetApplicationIntent (cmd))
log_to_txt ("openApp run with parameter =>" & cmd)

I would expect the app whose package name is = cmd to start
But this only works if the program is currently in the foreground
If the program is running in the background, the code runs ( i see the log message "openApp...") but nothing appears
 
Upvote 0
Top