zoukankan      html  css  js  c++  java
  • Android service里面启动alertdialog

     1 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" />

  • 相关阅读:
    路径
    aspx.cs调用js方法
    计算字符串中每种字母出现的次数
    [转载]获取2个集合List<T>的共同元素
    [转载]行列转换
    [转载]UNION合并查询
    [转载]Case When Then
    [转载]CAST-CONVERT两个函数进行类型转换时的异同点
    [转载]404错误页面设置
    [转载]JQ小知识
  • 原文地址:https://www.cnblogs.com/shuaiwen/p/2845947.html
Copyright © 2011-2022 走看看