对小米手机的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.youkuaiyun.com/shadow066/article/details/46342859