WindowManager.LayoutParams.TYPE_SYSTEM_ALERT 浮动窗适配问题

对小米手机的WindowManager 浮动窗时,出现一个问题,WindowManager.LayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,对此进行设置后,发现浮动窗弹出不了,没有异常发生,但是看不到!!!怎么办,网上一查,发现一个办法,前往“设置”——“应用”,在应用列表中找到“对应的app”,点击进入“应用信息”,开启“显示悬浮窗”,之后,可以正常使用。

把type 改为WindowManager.LayoutParams.TYPE_TOAST ,miui系统是可以了但是其他机型又会出现适配问题,想想能不能根据rom系统设置对应的type.

开始想到判断小米手机:String str = android.os.Build.BRAND;str="Xiaomi",当是小米手机时。但是考虑有的用户会刷机(miui)!我只能去判断系统是否是“MIUI”,

if(isMIUIRom()){

方法一:
wmParams.type = LayoutParams.TYPE_TOAST; //miui系统

方法二:

或者是调用Android系统“应用程序信息(Application Info)”界面

参考:http://jykenan.iteye.com/blog/1654925
}else{
wmParams.type = LayoutParams.TYPE_SYSTEM_ALERT; //其他大部分的系统
}

根据上面的判断以后,小米的和其他的机型都可以达到预期的效果了。

public static boolean isMIUIRom(){  
    String property = getSystemProperty("ro.miui.ui.version.name");  
    return !TextUtils.isEmpty(property);  
}  

public static String getSystemProperty(String propName) {  
   String line;  
   BufferedReader input = null;  
   try {  
       Process p = Runtime.getRuntime().exec("getprop " + propName);  
       input = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024);  
       line = input.readLine();  
       input.close();  
   } catch (IOException ex) {  
       return null;  
   } finally {  
       if (input != null) {  
           try {  
               input.close();  
           } catch (IOException e) {  
           }  
       }  
   }  
   return line;  
}  


上面MIUI判断方法参考

http://blog.csdn.net/shadow066/article/details/46342859



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值