Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anyway to forcefully use Mobile (Cellular) data? #159

Open
Okoken opened this issue Nov 25, 2023 · 0 comments
Open

Anyway to forcefully use Mobile (Cellular) data? #159

Okoken opened this issue Nov 25, 2023 · 0 comments

Comments

@Okoken
Copy link

Okoken commented Nov 25, 2023

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)
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant