安卓--请求网络链接判断网络状态--pizifusheng




public class NetStateUtil {


    public static boolean isConn(Context context){
        ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo info = (NetworkInfo) manager.getActiveNetworkInfo();
        if(info!=null && info.isAvailable()){
            return  true;
        }
        return false;
    }

    public  static void openDg(final Context context){
        AlertDialog.Builder builder=new AlertDialog.Builder(context);
        builder.setMessage("是否要进行网络连接设置?");
        builder.setPositiveButton("设置", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                Intent intent=null;
                //判断手机系统的版本  即API大于10 就是3.0或以上版本
                if(android.os.Build.VERSION.SDK_INT>10){
                    intent = new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS);
                }else{
                    intent = new Intent();
                    ComponentName component = new ComponentName("com.android.settings","com.android.settings.WirelessSettings");
                    intent.setComponent(component);
                    intent.setAction("android.intent.action.VIEW");
                }
                context.startActivity(intent);
            }
        });

        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {

            }
        });
        builder.create().show();

    }
}

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页