public void showSystemDialog(String showInfo, final int flag)
2 {
3 AlertDialog.Builder b = new AlertDialog.Builder(context);
4 b.setMessage(showInfo);
5 b.setPositiveButton("确定", new DialogInterface.OnClickListener()
6 {
7 public void onClick(DialogInterface dialog, int id)
8 {
9
10 switch (flag)
11 {
12 case 0:
13 Intent intent = new Intent(
14 Settings.ACTION_WIRELESS_SETTINGS);
15 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
16 context.startActivity(intent);
17 break;
18 case 1:
19
20 case 3: // 如果是GPRS,则提醒
21 if (moblieFlag == false)
22 {
23 moblieFlag = true;
24 }
25 default:
26 break;
27 }
28 d.dismiss();
29 }
30 }).setNegativeButton("取消", new DialogInterface.OnClickListener()
31 {
32 public void onClick(DialogInterface dialog, int id)
33 {
34 d.dismiss();
35 }
36 });
37 d = b.create();
38 d.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
39 d.show();
40
41 WindowManager.LayoutParams lp = d.getWindow().getAttributes();
42 WindowManager wm = (WindowManager) context
43 .getSystemService(Context.WINDOW_SERVICE);
44 Display display = wm.getDefaultDisplay();
45 if (display.getHeight() > display.getWidth())
46 {
47 lp.width = (int) (display.getWidth() * 1.0);
48 }
49 else
50 {
51 lp.width = (int) (display.getWidth() * 0.5);
52 }
53 d.getWindow().setAttributes(lp);
54 }
注意:增加权限 <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />