PowerTunnel-Android icon indicating copy to clipboard operation
PowerTunnel-Android copied to clipboard

Anyway to forcefully use Mobile (Cellular) data?

Open Okoken opened this issue 2 years ago • 0 comments

For some reason I always need to connect WIFI without network, then all the apps could not connect to network anymore even though Cellular data is still available. So it would be nice if PowerTunnel can create a Proxy forcefully using the Cellular data.

Are there any advices or hints to allow me add such function to the PowerTunnel?

Tried to add below function in MainActivity.onCreate or SplashActivity.onCreate, but PowerTunnel just crashed after clicking the button "Connect".

(coming from https://medium.com/@junaidtariq15cs/forcefully-use-mobile-cellular-data-when-both-wifi-and-mobile-data-are-on-in-the-android-app-877636fa02ab)

class MobileNetInit {
    @RequiresApi(Build.VERSION_CODES.O)
    fun changeNetworkToCellular(context: Context) {
        val connectMgr: ConnectivityManager =
            context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            val request: NetworkRequest.Builder = NetworkRequest.Builder()
            request.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR)
            connectMgr.requestNetwork(
                request.build(),
                object : ConnectivityManager.NetworkCallback() {
                    override fun onAvailable(network: Network) {
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                            connectMgr.bindProcessToNetwork(network)
                        }
                    }
                },20)
        }
    }
}

Okoken avatar Nov 25 '23 03:11 Okoken