ConnectivityManager manager = (ConnectivityManager) this .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = manager.getActiveNetworkInfo(); if (info != null && info.isAvailable()) { Toast.makeText(this, "网络可用", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "网络不可用", Toast.LENGTH_SHORT).show(); Intent intent = new Intent(); intent.setAction(Settings.ACTION_WIFI_SETTINGS); this.startActivity(intent); }
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
时间: 2024-10-10 04:44:40