问题描述
我想建立一个锁屏更换申请。有什么办法来创建一个监听器/服务,将推出我的应用程序,只要用户唤醒/解锁屏幕?
I want to build a lock screen replacement application. Is there any way to create a listener/service that would launch my app whenever the user wakes up/unlocks the screen?
推荐答案
见的,您需要使用DeviceAdminReceiver对于disableing默认的Android屏幕锁。
See source code of mylockforandroid and you will need use DeviceAdminReceiver for disableing default android screenlock.
用于启动活动时,用户解锁屏幕注册一个 Intent.ACTION_SCREEN_ON
和 Intent.ACTION_SCREEN_OFF
为:
for starting your activity when user unlock screen register an Intent.ACTION_SCREEN_ON
and Intent.ACTION_SCREEN_OFF
as:
在manifast.xml添加此code寄存器ScreenReceiver为:
add this code in manifast.xml register ScreenReceiver as:
<receiver android:name=".ScreenReceiver">
<intent-filter>
<action android:name="android.intent.action.SCREEN_OFF"/>
<action android:name="android.intent.action.SCREEN_ON"/>
</intent-filter>
</receiver>
和添加ScreenReceiver.java为:
and add an ScreenReceiver.java as:
public class ScreenReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_ON))
{
Intent intent = new Intent();
intent.setClass(context, ScreenLockActivity.class);
startActivity(intent);
}
}
}
这篇关于启动屏幕解锁Android应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!