锁屏下弹消息

本文介绍了一种在Android设备上实现特定应用程序在锁屏状态下自动启动并显示的方法。通过使用`WindowManager.LayoutParams`的多个标志,该应用程序可以在设备锁定时显示,并且能够关闭密钥保护、保持屏幕常亮等功能。



ava]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. protected void onCreate(Bundle savedInstanceState) {  
  2.     super.onCreate(savedInstanceState);  
  3.     final Window win = getWindow();  
  4.     win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED  
  5.             | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD  
  6.             | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON  
  7.             | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);  
  8.   
  9.     // 自己的代码  
  10. }  
  1. <activity android:name=".alarm.AlarmHandlerActivity"  
  2.           android:launchMode="singleInstance"  
  3.           android:excludeFromRecents="true"  
  4.           android:taskAffinity=""  
  5.           android:theme="@android:style/Theme.Wallpaper.NoTitleBar"/>  
[java]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1.     @Override  
  2.     public void onReceive(Context context, Intent intent) {  
  3.         Log.d(LOG_TAG, intent.getAction());  
  4.         KeyguardManager km = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);  
  5.         if (km.inKeyguardRestrictedInputMode()) {  
  6.             Intent alarmIntent = new Intent(context, AlarmActivity.class);  
  7.             alarmIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
  8.             context.startActivity(alarmIntent);  
  9.         }  
  10.     }  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值