Android Question Float display my app in front of others?

DannyRyan

Member
Licensed User
Longtime User
Hi,

Does anyone know if it is possible to display my app as a small floating app in front of another?

The closest example i can find on the internet can be seen in the app where the Gogolook (37 tags) is showing in front of the phone dialler screen.

Thanks for any help.


feature_realtime_search.png
 

bsnqt

Active Member
Licensed User
Longtime User
StandOut is perfect for this case, but it is chargeable (or donation).
I did an application similar to what you described, using kiosk mode (look for Erel's post).
The most challenging part you have to take care is how to display your app in front of the dialer screen during calls and during lock screen (if you want your app display even during lock screen).
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
The most challenging part you have to take care is how to display your app in front of the dialer screen during calls and during lock screen (if you want your app display even during lock screen).
Do you know how to display the window in front of selective apps and not all?
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
Do you know how to display the window in front of selective apps and not all?
If the app should run when receiving a call, you could use a BroadcastReceiver, but, the StandOut library should be used as well, yes, it is not free, I'm just answering the question. ;)
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
If the app should run when receiving a call, you could use a BroadcastReceiver, but, the StandOut library should be used as well, yes, it is not free, I'm just answering the question. ;)
I know. I am just trying to find out more useful information from @bsnqt . Maybe we can show the standout window only on Google Maps etc.
 
Upvote 0

bsnqt

Active Member
Licensed User
Longtime User
@thedesolatesould: it is exactly like NJDude mentioned, I just meant the dialer screen when you receive a call. The dialer screen's usual behaviour is to be always in front of all other apps. So the solution to be used is BroadcastReceiver (exactly like NJDude mentioned). I did my app in that way.

Your question, however, is very interesting for me. I have the same question that I have asked Erel before but I don't have yet answer.

Do you know how to display the window in front of selective apps and not all?

I cannot know the solution how to send my window in front of a selective app, but I do see many other apps can do, for example the app locker or protector. Let say you have an app named ABC. If you select ABC in the "protect list" of the Protector, every time when you run ABC, Protector will pop up a "locked screen" in front of ABC. And you have to enter the PIN to access ABC.

An idea just came in my mind is to use a timer and periodically check if ABC (or Google Map) is running then we can popup the StandOut in front of it? But the following piece of code only can tell us when ABC is running, I am not sure if this code can tell us ABC is in front. I need to test.

B4X:
Sub FindRunningProgram (Package As String)
    Dim sb As StringBuilder
    sb.Initialize
    Dim Phone As Phone
    Phone.Shell("ps", Null, sb, Null)
    Log(sb.ToString)
    Dim m As Matcher
    m = Regex.Matcher2("^[^ ]*\s+(\d+) .*" & Package, Regex.MULTILINE, sb.ToString)
    If m.Find Then
       Log(Package & " is running")
       Return True
    Else
       Log(Package & " is NOT running")
       Return False
    End If
End Sub
 
Last edited:
Upvote 0

NJDude

Expert
Licensed User
Longtime User
I haven't tested that code but if you can determine that the app is running then after that ask if the main activity is paused (If IsPaused(Main) = False Then ...) that way it will bring it to the front, but in the case of the dialer I don't think that would work.
 
Upvote 0

bsnqt

Active Member
Licensed User
Longtime User
I haven't tested that code but if you can determine that the app is running then after that ask if the main activity is paused (If IsPaused(Main) = False Then ...) that way it will bring it to the front, but in the case of the dialer I don't think that would work.

You're totally correct. In my app that I worked in the past (with a very similar situation, like in the very first post from DannyRyan, i.e display a note during a call), I could not get my main activity in front of call screen. At that time, I did not know the StandOut library. So in order to display a note similar to what that is asked by DannyRyan, I have to use the CustomToast with help of RichStringBuilder...

Something like the following (pseudo code, extracted from my project):

B4X:
       Dim rs As RichString
    Dim rsb As RichStringBuilder
    Dim btmp1 As Bitmap
    rs.Initialize("")
    rsb.Initialize
    rsb.Append(rs)
    rsb.Append(“Here is your string to display”)
    rs.Initialize(rsb)
    ‘// Here I played with codes working on rs, btmp1 etc...
    Dim autodisplay As CustomToast
    autodisplay.Initialize
    Dim time As Int
    '// I can display the toast during a time that I can control
    Select Case Time
        Case 5 ‘ display 5 sec.
            time = 5000
        Case 8 ‘ display 8 sec.
            time = 8000
        Case 10 ‘ display during 10 sec.
            time = 10000
    End Select  
    autodisplay.ShowBitmap(rs,time,Gravity.TOP,0,0,btmp1)

Screen.png
 
Last edited:
Upvote 0
Top