Android检查Internet是否可以正常连接

来源:互联网 发布:淘宝卖家代销能不能刷 编辑:程序博客网 时间:2024/04/28 14:06
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) { // 提示使用wifiToast.makeText(context.getApplicationContext(), "你没有使用WIFI连接Internet,建议您使用WIFI以减少流量!", Toast.LENGTH_SHORT).show();}return isAvalible;}

原创粉丝点击