今天,想做这个跳转到网络设置界面, 刚开始用
intent =
new
Intent(Settings.ACTION_WIRELESS_SETTINGS);
不料老是出现settings.WirelessSettings找不到(就是没法提示出来,显示红色底纹),我后来查了下资料,结果发现跟版本有关,我的是安卓4.3的,所以需要用
intent =
new
Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
// 加权限<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE">
/*
* 判断网络连接是否已开
* true 已打开 false 未打开
* */
public
static
boolean
isConn(Context context){
boolean
bisConnFlag=
false
;
ConnectivityManager conManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo network = conManager.getActiveNetworkInfo();
if
(network!=
null
){
bisConnFlag=conManager.getActiveNetworkInfo().isAvailable();
}
return
bisConnFlag;
}
/**
* 当判断当前手机没有网络时选择是否打开网络设置
* @param context
*/
public
static
void
showNoNetWorkDlg(
final
Context context) {
AlertDialog.Builder builder =
new
Builder(context);
builder.setIcon(R.drawable.ic_launcher)
//
.setTitle(R.string.app_name)
//
.setMessage(
"当前无网络"
).setPositiveButton(
"设置"
,
new
OnClickListener() {
@Override
public
void
onClick(DialogInterface dialog,
int
which) {
// 跳转到系统的网络设置界面
Intent intent =
null
;
// 先判断当前系统版本
if
(android.os.Build.VERSION.SDK_INT >
10
){
// 3.0以上
intent =
new
Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS);
}
else
{
intent =
new
Intent();
intent.setClassName(
"com.android.settings"
,
"com.android.settings.WirelessSettings"
);
}
context.startActivity(intent);
}
}).setNegativeButton(
"知道了"
,
null
).show();
}</uses-permission>
|