//Code by canyie
javags(SDK_INT,null,"android.os.Build$VERSION","SDK_INT")
s canDraw = false
f(SDK_INT >= 23)
{
//6.0及以上,调用Settings.canDrawOverlays
java(canDraw,null,"android.provider.Settings.canDrawOverlays","Context",activity)
}
else f(SDK_INT < 19)
{
//4.4以下,不检测
s canDraw = true
}
f(!canDraw && SDK_INT >= 19)
{
//拿AppOpsManager再检测一次
//一是6.0以下无法使用Settings.canDrawOverlays
//二是8.0时存在一个bug,更改悬浮窗权限不会立即反映过来
//所以拿AppOpsManager再试试(听说没用)
java(appops,activity,"android.app.Activity.getSystemService","String","appops")
f(appops == null)
{
syso("no AppOpsManager")
s canDraw = true
//拿不到AppOpsManager,默认true
}
else
{
java(pn,activity,"android.content.Context.getPackageName")
java(uid,null,"android.os.Process.myUid")
java(mode,appops,"android.app.AppOpsManager.noteOpNoThrow","int",24,"int",uid,"String",pn)
f(mode == 0)
{
s canDraw = true
}
}
}
tw(canDraw)