Androidはインターネットが正常に接続できるかどうかをチェックします
923 ワード
public boolean note_Intent(Context context) {
ConnectivityManager con = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkinfo = con.getActiveNetworkInfo();
boolean isAvalible = false;
if (networkinfo == null || !networkinfo.isAvailable()) {
//
Toast.makeText(context.getApplicationContext(), " Internet, Internet!", Toast.LENGTH_SHORT).show();
return false;
}
if (networkinfo != null && networkinfo.isConnected()) {
if (networkinfo.getState() == NetworkInfo.State.CONNECTED) {
isAvalible = true;
}
}
boolean wifi = con.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting();
if (!wifi) { // wifi
Toast.makeText(context.getApplicationContext(), " WIFI Internet, WIFI !", Toast.LENGTH_SHORT).show();
}
return isAvalible;
}