Android Question Error in requesting wifi ssid

This is my code below plus the error im getting pls anyone help me


android.app.RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{4c29268 u0 com.Danjummai.hikma/.wifi12}
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1760)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6810)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
Wifi ssid:
#Region  Service Attributes
    #StartAtBoot: True
    
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private myTorch As flashTorch
    Dim WiFi1 As MLwifi

    Dim  now As Long
    Dim  d,m As String
    DateTime.DateFormat = "dd:mm "
    Dim icomph As  String 
    Dim Sms As PhoneSms
    'Dim ajiya As List
    'Dim ajiya2 As List
    'Dim ajiya3 As String
    'THE CODE FOR OPNING LINK Dim phoneintents As PhoneIntents
    
    
    Dim SSID As String
    Dim r As Reflector
    Dim WiFi1 As MLwifi
    Public kunna As String
    Dim p As Phone
    Dim rp As RuntimePermissions
      Dim R As Reflector
    Dim SSID As String

End Sub

Sub Service_Create
    'rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
    rp.CheckAndRequest(rp.PERMISSION_ACCESS_COARSE_LOCATION)
    
    myTorch.Initialize
End Sub

Sub Service_Start (StartingIntent As Intent)
    
 
    StartServiceAt(ChangeVolume,10,True)
    Service.StopAutomaticForeground 'Call this when the background task completes (if there is one)
End Sub

Sub CheckWiFi
    
    
    'If WiFi1.isWifiEnabled = True And WiFi1.isSavedWifiAP("Redmi") = True Then
           'WiFi1.connectWifiAP("Redmi")
    
        
    'Else
        'If    WiFi1.isWifiEnabled = True And  WiFi1.WifiSSID == "" Then
        
        'If WiFi1.saveWifiAP("Redmi", 0 ,"",True) = True Then
            'WiFi1.connectWifiAP("Redmi")
            
    '    End If
    '    End If
        
    'End If
    
    
     If    WiFi1.isWifiEnabled = True And  WiFi1.WifiSSID == "Redmi" Then
        P.SetRingerMode(p.RINGER_SILENT)
        kunna = "cn"
        
    Else If    WiFi1.isWifiEnabled = True And  WiFi1.WifiSSID == "" Then
        P.SetRingerMode(p.RINGER_Normal)
    End If
    If myTorch.isTorchSupported Then
        'Yes!, take control of the camera!
        myTorch.initTorch
    Else
        
        'MsgboxAsync("Your device doesn't support Torch mode","Torch ERROR")
    End If
    If    WiFi1.isWifiEnabled = True And  WiFi1.WifiSSID == "Redmi" Then
        If Starter.torch = "on" Then
            myTorch.Torch=True
        Else
            myTorch.Torch=False
        End If
        
    End If
    #if b4i
    If  baya.ajiya.Get(0) <> False  Then
        baya.s.Send(baya.ajiya.Get(0), "I am praying right now, try reaching me later on . @Danj soft")
        baya.ajiya.Clear
    End If
  
    #End if
    
    
    
    
    d =  DateTime.GetHour(DateTime.Now)
    m = DateTime.GetMinute(DateTime.Now)
    If d = 2 And m = 1 Then
        WiFi1.EnableWifi(True)
        
    Else If d = 17 And m = 5 Then
        
    Else If d = 26 And m = 2 Then
    
    Else If d = 19 And m = 12 Then
        
    Else If d = 30 And m = 4 Then
        
        
    End If

    
    
    
    
End Sub
Sub Mugu
    If p.SdkVersion >= 27 Then
        If WiFi1.isWifiEnabled = True Then
               StartActivity(Main)
            R.Target = R.GetContext
            Try
                R.Target = R.RunMethod2("getSystemService", "wifi", "java.lang.String")
                R.Target = R.RunMethod("getConnectionInfo")
                R.Target = R.RunMethod("getSSID")
      
                If R.Target <> Null Then
                    SSID = R.Target
                    SSID = SSID.SubString2(1, SSID.Length - 1)
                    If SSID.Contains("unknown") Then SSID = "" 'From android 8.0 onwards we get SSID only if GPS is turned on, otherwise "<unknown ssid>".
                    If SSID = "Redmi" Then
                        P.SetRingerMode(p.RINGER_SILENT)
                        WiFi1.EnableWifi(True)
                    Else If SSID = "" Then
                        P.SetRingerMode(p.RINGER_Normal)
                
                
                    End If
                Else
          
                End If
            Catch
                Dim b As String
            End Try
        End If
    End If
End Sub
Sub ChangeVolume
    Dim p As Phone
    If p.SdkVersion >= 24 Then
        Dim NotificationManager As JavaObject
        NotificationManager = NotificationManager.InitializeContext.RunMethod("getSystemService", Array("notification"))
        If NotificationManager.RunMethod("isNotificationPolicyAccessGranted", Null) = False Then
            Dim in As Intent
            in.Initialize("android.settings.NOTIFICATION_POLICY_ACCESS_SETTINGS", "")
            Sleep(500) 'let the first Activity_Resume be handled. Important if this code is called from Activity_Create.
            StartActivity(in)
            Wait For Service_resume
            Log("after resume")
            If NotificationManager.RunMethod("isNotificationPolicyAccessGranted", Null) = False Then
                Log("no permission")
                Return
            End If
        End If

    End If
    p.SetVolume(p.VOLUME_RING, p.GetMaxVolume(p.VOLUME_RING), False)
    p.SetVolume(p.VOLUME_MUSIC, 3, True)
    p.SetRingerMode(p.RINGER_SILENT)
End Sub
Dim p As Phone
p.SetVolume(p.VOLUME_MUSIC, 3, True)

Sub Service_Destroy

End Sub
 
No button is being used to start the button, its just that the service start on boot and then i set this code to run every 10 sec like this

pls help i'm a noob to b4a
Sub mugu:
Sub Mugu
    If p.SdkVersion >= 27 Then
        If WiFi1.isWifiEnabled = True Then
               StartActivity(Main)
            R.Target = R.GetContext
            Try
                R.Target = R.RunMethod2("getSystemService", "wifi", "java.lang.String")
                R.Target = R.RunMethod("getConnectionInfo")
                R.Target = R.RunMethod("getSSID")
      
                If R.Target <> Null Then
                    SSID = R.Target
                    SSID = SSID.SubString2(1, SSID.Length - 1)
                    If SSID.Contains("unknown") Then SSID = "" 'From android 8.0 onwards we get SSID only if GPS is turned on, otherwise "<unknown ssid>".
                    If SSID = "Redmi" Then
                        P.SetRingerMode(p.RINGER_SILENT)
                        WiFi1.EnableWifi(True)
                    Else If SSID = "" Then
                        P.SetRingerMode(p.RINGER_Normal)
                
                
                    End If
                Else
          
                End If
            Catch
                Dim b As String
            End Try
        End If
    End If
End Sub
B4X:
Sub Service_Start (StartingIntent As Intent)
    
 
    StartServiceAt(Mugu,10,True)
    Service.StopAutomaticForeground 'Call this when the background task completes (if there is one)
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…