Hello, everyone I'm posting a question after a long time. When I try to watch a video when I'm accessing lte or 3g, there's a part that says yes/no in the dialog because it's 3g/4g, but how do I implement this part? I'm looking it up on Google, but it's hard to implement. I'm going to apply this to YouTube, but I want to make a dialog appear when I click on YouTube play Please help me if you know!
android java
In order to display the dialog you mentioned, it is necessary to verify that the mobile connection is enabled (3g/4g...) and that the Wi-Fi is enabled. The mobile connection is connected, and when the Wi-Fi connection is not connected, you can display the corresponding dialog. Please refer to the following code. (No other exceptions were made for explanation)
ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
boolean isMobile = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting();
boolean isWifi = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting();
if (isMobile && !isWifi) {
// Dialogue to launch a treatment.
}
© 2024 OneMinuteCode. All rights reserved.