【问题标题】:Android Display own lock instead of default when screen on/offAndroid 在屏幕开/关时显示自己的锁定而不是默认锁定
【发布时间】:2014-04-12 05:04:22
【问题描述】:
我想打开我创建的锁而不是默认锁,当手机启动时我的锁被调用。但是我想知道我的屏幕在锁定后何时打开我如何调用我的锁定(我的锁定活动)意味着我想在屏幕打开或手机重启或一直打开时显示我的锁定而不是默认值。就像在我们的电话锁中一直调用一样,就像我想一直调用我的锁一样(通过启动完成)。所以请任何人帮助我在屏幕开/关时如何调用我的锁。请快速帮助谢谢....在启动时调用我的锁,正是我想要的屏幕开/关
{ <receiver
android:name=".BootReciever"
android:enabled="true"
android:exported="true" >
<intent-filter android:priority="1" >
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver> } in menifest
【问题讨论】:
标签:
android
locking
broadcastreceiver
【解决方案1】:
我自己给出答案:在我的 BootReciever 类中使用以下方法:
`enter code here`
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if (intent.getAction() != null) {
if (intent.getAction().equals(Intent.ACTION_USER_PRESENT)) {
Intent s = new Intent(context,ViewPagerMainActivity.class);
s.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(s);
}
}
}
并在清单文件中使用以下内容:
enter code here : use : <action android:name="android.intent.action.USER_PRESENT" />
<receiver
android:name=".BootReciever"
android:enabled="true"
android:exported="false" >
<intent-filter android:priority="1" >
<action android:name="android.intent.action.SCREEN_ON" />
<action android:name="android.intent.action.SCREEN_OFF" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>