android可以有一个悬浮窗口在进入屏保状态显示,点击进入应用,Android如何实现锁屏状态下弹窗...

前言

想在锁屏上面实现弹窗,第一个想法就是利用 WindowManager设置 Window的 Flag,通过设置 Flag的显示优先级来让窗口显示在锁屏的上面。

接下来就是试验可能相关的 Window Type属性,验证该方案是否可行。

在尝试各个 Window Type 属性之前需要明确各个 Type 所需要的权限,下面是 com.android.internal.policy.impl.PhoneWindowManager.checkAddPermission 的源码:

public int checkAddPermission(WindowManager.LayoutParams attrs) {

int type = attrs.type;

if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW

|| type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) {

return WindowManagerImpl.ADD_OKAY;

}

String permission = null;

switch (type) {

case TYPE_TOAST:

// XXX right now the app process has complete control over

// this... should introduce a token to let the system

// monitor/control what they are doing.

break;

case TYPE_INPUT_METHOD:

case TYPE_WALLPAPER:

// The window manager will check these.

break;

case TYPE_PHONE:

case TYPE_PRIORITY_PHONE:

case TYPE_SYSTEM_ALERT:

case TYPE_SYSTEM_ERROR:

case TYPE_SYSTEM_OVERLAY:

permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;

break;

default:

permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;

}

if (permission != null) {

if (mContext.checkCallingOrSelfPermission(permission)

!= PackageManager.PERMISSION_GRANTED) {

return WindowManagerImpl.ADD_PERMISSION_DENIED;

}

}

return WindowManagerImpl.ADD_OKAY;

}

明显不适合的 Type:TYPE_TOAST, TYPE_INPUT_METHOD, TYPE_WALLPAPER; 可能适合的 Type:TYPE_PHONE, TYPE_PRIORITY_PHONE, TYPE_SYSTEM_ALERT, TYPE_SYSTEM_ERROR, TYPE_SYSTEM_OVERLAY; 其它类型的 Type:

需要系统签名权限:

android.Manifest.permission.INTERNAL_SYSTEM_WINDOW

而申请该权限需要系统签名,所以我们是无法获取权限的。

TYPE_PHONE

/**

* Window type: phone. These are non-application windows providing

* user interaction with the phone (in particular incoming calls).

* These windows are normally placed above all applications, but behind

* the status bar.

* In multiuser systems shows on all users' windows.

*/

public static final int TYPE_PHONE = FIRST_SYSTEM_WINDOW+2;

TYPE_PHONE 类型的窗口可以显示在其它 APP 的上面,但不能显示在锁屏的上面,所以 PASS。

TYPE_PRIORITY_PHONE

/**

* Window type: priority phone UI, which needs to be displayed even if

* the keyguard is active. These windows must not take input

* focus, or they will interfere with the keyguard.

* In multiuser systems shows on all users' windows.

*/

public static final int TYPE_PRIORITY_PHONE = FIRST_SYSTEM_WINDOW+7;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值