Hi dears!
I know that there are a lot of deprecated APIs since SDK version 29 and above while trying to find out if an app is running in background or in foreground.
This also includes some libs like i. e. UsageStatsManager or code like this:
Also permissions like these two here...
... are deprecated.
In my case, I have to know if my app is in foreground (visible) or not. There is a service in my app which informs the user via screen note that my app is in a so called "protection mode". If the app is in foreground, there is no need to inform the user... only in case my app is in background.
What should I do now ... or could I do?
I am thankful for any help.
Best regards
I know that there are a lot of deprecated APIs since SDK version 29 and above while trying to find out if an app is running in background or in foreground.
This also includes some libs like i. e. UsageStatsManager or code like this:
B4X:
Sub appIsInBackground As Boolean
Dim ActMan As JavaObject
Dim R As Reflector
R.Target = R.GetContext
ActMan = R.RunMethod2("getSystemService","activity","java.lang.String")
Dim TaskInfo As JavaObject = ActMan.RunMethod ("getRunningTasks", Array As Object(1))
Dim CompInfo As JavaObject = TaskInfo.RunMethodJO ("get", Array As Object(0)).GetField("topActivity")
Dim PackageName As String = CompInfo.RunMethod ("getPackageName", Null)
Log(PackageName.ToLowerCase)
Return Not(PackageName.ToLowerCase.Contains("ba.example"))
End Sub
Also permissions like these two here...
B4X:
AddPermission(android.permission.GET_ACCOUNTS)
AddPermission(android.permission.GET_TASKS)
... are deprecated.
In my case, I have to know if my app is in foreground (visible) or not. There is a service in my app which informs the user via screen note that my app is in a so called "protection mode". If the app is in foreground, there is no need to inform the user... only in case my app is in background.
What should I do now ... or could I do?
I am thankful for any help.
Best regards