Android Question Diagnosis on vpn

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Sub ListNetworkCapabilities
   Dim p As Phone
   If p.SdkVersion >= 21 Then
       Dim ctxt As JavaObject
       ctxt.InitializeContext
       Dim manager As JavaObject = ctxt.RunMethod("getSystemService", Array("connectivity"))
       Dim networks() As Object = manager.RunMethod("getAllNetworks", Null)
       For Each network As JavaObject In networks
           Dim capabilities As JavaObject = manager.RunMethod("getNetworkCapabilities", Array(network))
           Log(capabilities)
           Dim IsVPN As Boolean = capabilities.RunMethod("hasTransport", Array(4)) 'TRANSPORT_VPN
           Log("IsVPN: " & IsVPN)
       Next
   End If
End Sub

Manifest editor:
B4X:
AddPermission(android.permission.ACCESS_NETWORK_STATE)

Based on: https://stackoverflow.com/a/35274808/971547
 
Upvote 0
Top