try { ConnectivityManager manager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = manager.getActiveNetworkInfo(); if (info == null) { // 网络关闭 Toast.makeText(this, "没网络", Toast.LENGTH_SHORT).show(); } else { // 网络开启 // 判断网络是wifi还是mobileNetworkInfo wifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (wifi != null && wifi.isConnected()) { Toast.makeText(this, "wifi网络", Toast.LENGTH_SHORT).show(); video.setUp("http://2449.vod.myqcloud.com/2449_22ca37a6ea9011e5acaaf51d105342e3.f20.mp4", JCVideoPlayerStandard.SCREEN_LAYOUT_NORMAL, "嫂子闭眼睛"); } NetworkInfo mobile = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (mobile != null && mobile.isConnected()) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("当前是4G加载是否继续"); builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { video.setUp("http://2449.vod.myqcloud.com/2449_22ca37a6ea9011e5acaaf51d105342e3.f20.mp4", JCVideoPlayerStandard.SCREEN_LAYOUT_NORMAL, "嫂子闭眼睛"); } }); builder.setNegativeButton("取消",null); AlertDialog dialog = builder.create(); dialog.show(); } } } catch (Exception e) { e.printStackTrace(); }
判断是Wifi联网,还是手机联网
最新推荐文章于 2023-04-19 15:48:04 发布