Android Question How to make not full screen app, i.e. panel only

Adamdam

Active Member
Licensed User
Longtime User
Dear all,
Greetings,

In b4a how to make app converted from full screen to be a panel? Say "panel1" and continue on the screen as can be done (for android and Huawei devices).

best regards
 

Adamdam

Active Member
Licensed User
Longtime User
Apps are hosted in activities. You cannot host an app in a panel.
Dear Engr. Erel,

Thank you very much for your kind support and assistance.

I would greatly appreciate your advice regarding a challenge I am currently facing.

I am developing an Internet Radio application that streams audio from an online source and plays it locally on the device. My objective is to allow the application to continue running in the background indefinitely, even when minimized.

Ideally, I would like the application to behave similarly to popular music streaming apps, where it can be minimized to a small icon or remain accessible through the notification bar while continuing playback. The streaming should continue until the user explicitly presses the Pause or Stop button.

Could you kindly suggest the best approach to achieve this functionality?

I look forward to your valuable guidance.

Best regards,
 
Upvote 0

Adamdam

Active Member
Licensed User
Longtime User
In this example you will find what you need to achieve what you are searching for.
https://www.b4x.com/android/forum/threads/background-location-tracking.99873/
I tested it and even tried to modified two things : first send (lat, Long) to server but not worked, also trie to load image to notification bar but also not worked, any help, please , the code as following <code>
#Region Service Attributes
#StartAtBoot: False
#End Region

Sub Process_Globals
Private nid As Int = 1
Private GPS As GPS
Private Tracking As Boolean = False
Private lock As PhoneWakeState
Private ServerURL As String = "http://192.168.1.116/TrackSon/api.php"
Private UpdateTimer As Timer
Private LastLocation As Location
Private HasLocation As Boolean = False
End Sub

Sub Service_Create
Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER
GPS.Initialize("gps")
lock.PartialLock

' ── Timer:
UpdateTimer.Initialize("UpdateTimer", 5000)
UpdateTimer.Enabled = False
End Sub

Sub Service_Start(StartingIntent As Intent)
Service.StartForeground(nid, CreateNotification("جاري تحديد الموقع..."))
Track
End Sub

Public Sub Track
If Tracking Then Return
If Starter.rp.Check(Starter.rp.PERMISSION_ACCESS_FINE_LOCATION) = False Then
Log("No permission")
Return
End If
GPS.Start(0, 0)
Tracking = True
UpdateTimer.Enabled = True
Log("GPS started, Timer started")
End Sub


Sub UpdateTimer_Tick
If HasLocation = False Then
Log("Timer tick — no location yet")
UpdateNotification("في انتظار GPS...")
Return
End If
Log("Timer tick — sending location")
DoUpdate(LastLocation)
End Sub

Sub GPS_LocationChanged(Location1 As Location)
Log("GPS LocationChanged")
LastLocation = Location1
HasLocation = True
End Sub

Private Sub DoUpdate(Location1 As Location)
Try
DateTime.DateFormat = "yyyy-MM-dd"
DateTime.TimeFormat = "HH:mm:ss"
Dim currentTime As String = DateTime.Time(DateTime.Now)
Dim body As String = $"Lat: $2.5{Location1.Latitude} / $2.5{Location1.Longitude}${CRLF}Last update : ${currentTime}"$
UpdateNotification(body)
Log(body)
SendLocationToServer(Location1)
Catch
Log("DoUpdate error: " & LastException)
End Try
End Sub

Private Sub UpdateNotification(Body As String)
Dim n As Notification = CreateNotification(Body)
n.Notify(nid)
End Sub

Sub SendLocationToServer(Location1 As Location)
Dim link As String = ServerURL & _
"?device_id=test123" & _
"&lat=" & NumberFormat2(Location1.Latitude, 1, 6, 6, False) & _
"&lng=" & NumberFormat2(Location1.Longitude, 1, 6, 6, False)
Log(link)
Dim job As HttpJob
job.Initialize("send", Me)
job.Download(link)
End Sub

Sub JobDone(Job As HttpJob)
If Job.Success Then
Log("SUCCESS: " & Job.GetString)
Else
Log("FAILED: " & Job.ErrorMessage)
End If
Job.Release
End Sub

'═══════════════════════════════════════════════════════════════════════
' Notification — الحل الصحيح للصورة عبر RemoteViews
'═══════════════════════════════════════════════════════════════════════
Sub CreateNotification(Body As String) As Notification
Dim notification As Notification
notification.Initialize2(notification.IMPORTANCE_LOW)
notification.Icon = "icon"
notification.SetInfo("Tracking location :", Body, Main)

' ── Large Icon عبر NotificationCompat builder ──
Try
Dim bmp As Bitmap = LoadBitmap(File.DirAssets, "imgPlay.png")

Dim jo As JavaObject = notification
Dim builder As JavaObject

Dim found As Boolean = False
For Each fname As String In Array As String("builder", "mBuilder")
Try
builder = jo.GetField(fname)
If builder.IsInitialized Then
Dim androidBmp As JavaObject = bmp
builder.RunMethod("setLargeIcon", Array(androidBmp))
Log("LargeIcon set via: " & fname)
found = True
Exit
End If
Catch
Log("Field '" & fname & "' not found")
End Try
Next

If found = False Then
Try
jo.RunMethod("setLargeIcon", Array(bmp))
Log("LargeIcon set directly")
Catch
Log("Direct setLargeIcon failed: " & LastException.Message)
End Try
End If

Catch
Log("CreateNotification image ERR: " & LastException.Message)
End Try

Return notification
End Sub

Sub Service_Destroy
UpdateTimer.Enabled = False
If Tracking Then GPS.Stop
Tracking = False
lock.ReleasePartialLock
End Sub </code>
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
It will need time to create a project adding even your code to test.
Do you have any error while trying to upload something to your server?
You need to provide such informations to let anyone try to understand what the problem could be.
Or if something just fail without messages or crashes.
Try modifying your upload sub to this
B4X:
Sub SendLocationToServer(Location1 As Location)
    Dim link As String = ServerURL & _
    "?device_id=test123" & _
    "&lat=" & NumberFormat2(Location1.Latitude, 1, 6, 6, False) & _
    "&lng=" & NumberFormat2(Location1.Longitude, 1, 6, 6, False)
    Log(link)
    Dim job As HttpJob
    job.Initialize("send", Me)
    job.Download(link)
    job.GetRequest.SetHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36")
    Wait For (job) JobDone(myjob As HttpJob)
    If Job.Success Then
        Log("SUCCESS: " & Job.GetString)
    Else
        Log("FAILED: " & Job.ErrorMessage)
    End If
    Job.Release
End Sub
The Sub JobDone is not needed.
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
Just my 2 cents.....
For such an app I see far better the use of a well designed widget, to have direct commands and the ability to show a nice UI with the song name and (eventually) the cover image, the duration.....
Of course this mean a quite new project.

P.S.= when posting code please use the </> icon to attach it in code form for readability.
 
Upvote 0
Top