问题描述
我有一些意图.当意图触发时,我想发送一个像 AlertBox 这样的弹出通知并打开屏幕让用户立即看到通知(我的意思是不显示锁屏).
例如,如果您使用过 HandcentSMS,那么您就会明白我的意思(就像接受消息时的弹出通知)
如何组织?任何代码示例?我必须使用什么样的权限?
提前致谢.
推荐答案
也许 KeyguardLock 会做你想做的事:弹出你的通知,然后调用 disableKeyguard,然后在用户完成或超时后重新启用.
从安全角度来说,这有点危险,但你去吧.
其他推荐答案
查看电源管理器.
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag"); wl.acquire(); //Do whatever you need right here wl.release();
其他推荐答案
你的activity在onCreate()实现中应该有以下代码:
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); setContentView( R.layout.myLayout); // rest of initialization }
您使用意图调用活动.下面是一个例子:
Intent startIntent = new Intent(context, MyActivity.class); startIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(startIntent);
问题描述
I have some Intent. When intent fires, I want to send a popup notification like an AlertBox and turn screen ON to let User see the notification immediately (I mean without showing a lockscreen).
If you've used, for example, HandcentSMS then you understand what I mean (like a popup notification when accept a message)
How to organize this? Any code examples? What kind of permissions I have to use?
Thank you in advance.
推荐答案
Perhaps KeyguardLock will do what you want: popup your notification and then call disableKeyguard, then re-enable when the user is done or after you time out.
Security-wise it is a little risky, but there you go.
其他推荐答案
Check out PowerManager.
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag"); wl.acquire(); //Do whatever you need right here wl.release();
其他推荐答案
Your activity should have the following code in onCreate() implementation:
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); setContentView( R.layout.myLayout); // rest of initialization }
You invoke the activity using an intent. Here is an example:
Intent startIntent = new Intent(context, MyActivity.class); startIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(startIntent);