判断当前网络是否可用和调用系统设置wifi界面
需要用到的权限
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.INTERNET"/>
//判断当前网络是否可用 public boolean note_Intent(Context context) { ConnectivityManager con = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkinfo = con.getActiveNetworkInfo(); if (networkinfo == null || !networkinfo.isAvailable()) { // 当前网络不可用 Toast.makeText(context.getApplicationContext(), "当前网络不可用", Toast.LENGTH_SHORT).show(); return false; } boolean wifi = con.getNetworkInfo(ConnectivityManager.TYPE_WIFI) .isConnectedOrConnecting(); if (!wifi) { // 提示使用wifi Toast.makeText(context.getApplicationContext(), "建议您使用WIFI以减少流量!", Toast.LENGTH_SHORT).show(); } return true; }
跳转到系统设置WIFI界面中
Intent localIntent = new Intent(); localIntent.setComponent(new ComponentName("com.android.settings", "com.android.settings.wifi.WifiPickerActivity")); startActivityForResult(localIntent, 100);
相关推荐
huha 2020-10-16
xfcyhades 2020-11-20
sgafdsg 2020-11-04
Michael 2020-11-03
fengyeezju 2020-10-14
ziyexiaoxiao 2020-10-14
业余架构师 2020-10-09
OuNuo0 2020-09-29
moses 2020-09-22
Angelia 2020-09-11
qinxu 2020-09-10
刘炳昭 2020-09-10
Nostalgiachild 2020-09-07
Nostalgiachild 2020-08-17
leavesC 2020-08-14
一青年 2020-08-13
AndroidAiStudy 2020-08-07
ydc0 2020-07-30
绿豆饼 2020-07-28