本文介绍了ACTION_USER_ preSENT清单中与BroadcastReceiver的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
人们似乎对是否有可能赶上ACTION_USER_ preSENT屏幕通过清单解锁不同的意见。
There seems to be different opinions on whether it is possible to catch the ACTION_USER_PRESENT screen unlock through the manifest.
该线程意味着没有它不能做的:
This thread implies no it can't be done:
该线程意味着肯定是可以做到的:
This thread implies yes it can be done:
广播Reciever为ACTION_USER_ preSENT,ACTION_SCREEN_ON,ACTION_BOOT_COMPLETED
我不能够获得事件无论是2.3.3或3.2模拟器的工作。
I'm not able to get the event working with either a 2.3.3 or 3.2 emulator.
别人也有最近的经验呢?也许一个code样品分享?
Does anyone else have recent experience with this? And perhaps a code sample to share?
推荐答案
使用一个接收器:
public class Receive extends BroadcastReceiver {
if (intent.getAction() != null) {
if
( intent.getAction().equals(Intent.ACTION_USER_PRESENT)) {
Intent s = new Intent(context, MainActivity.class);
s.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(s);
}}
而在你的清单:
And in your manifest:
<receiver android:name=".Receive">
<intent-filter android:enabled="true" android:exported="false">
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
这篇关于ACTION_USER_ preSENT清单中与BroadcastReceiver的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!