Android Question [SOLVED] - About Airplane Mode and Toggle ownership.

Jmu5667

Well-Known Member
Licensed User
Longtime User
Hello

We work with a number of phone manufacturers and have been given signing keys that allow our apps become system apps. One issue we are solving is the abaility to toggle Airplane Mode on/off to allow us reset the data connection on phones if we detect we have no data. This can occur and the toggling of AP mode fix's the issue when this occurs.

I have noticed this morning during testing of different senarios that if I manually set airplane on in the settings, our app can turn if off, but it comes back on again. Does anyone have any insights ino this. I am thinking that the app that turns it on it the app that can turn it off.

Btw, our app can toggle if on and off no problem, if AP mode was off.

Regards

John.

[SOLVED]

B4X:
Manifest
AddPermission(android.permission.WRITE_SECURE_SETTINGS)

Sub SetAirplaneMode(On As Boolean)
    
    Dim p As Phone
    Dim r As Reflector
    Dim contentResolver As Object
    
    r.Target = r.GetContext
    contentResolver = r.RunMethod("getContentResolver")
    Dim state As Int
    ' // turn off
    If Not(On) Then
        state = 0
    Else
        ' // turn on
        state = 1
    End If

    r.RunStaticMethod("android.provider.Settings$Global", "putInt", _
        Array As Object(contentResolver, "airplane_mode_on", state), _
        Array As String("android.content.ContentResolver", "java.lang.String", "java.lang.int"))
    
    Try
        Dim i As Intent
        i.Initialize("android.intent.action.AIRPLANE_MODE", "")
        i.PutExtra("state", On)
        p.SendBroadcastIntent(i)
    Catch
        log($"mod_functions::SetAirplaneMode(${On}) - error ${LastException.Message}"$)
    End Try
    

    
End Sub
 
Last edited:
Top