Code is needed: When a user presses a button, it checks whether it is connected to the Internet, if not - a message is displayed with two options: connect to the Internet (settings open) or exit the application.
1 answer
Try this:
public boolean checkConnection() { ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); return netInfo != null && netInfo.isConnectedOrConnecting(); } Just do not forget to register in the manifest <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
This will determine the connection to the general Internet, and not just to wi-fi
|