我想要开发一个锁屏替换应用程序。有没有办法创建一个监听器/服务,每当用户唤醒/解锁屏幕时就启动我的应用程序?
ACTION_USER_PRESENT
意图操作。
话虽如此,Android目前不支持替换锁屏。市场上任何声称可以做到这一点的应用程序都利用了安全漏洞,因此不安全。您可以阅读此帖子以获取更多信息(特别是要阅读Mark Murphy的帖子)。抱歉。public static final String ACTION_USER_PRESENT
自API Level 3起 广播操作:当设备唤醒后用户出现时发送广播(例如,当键盘保护程序消失时)。
Intent.ACTION_SCREEN_ON
和Intent.ACTION_SCREEN_OFF
注册为:
在manifest.xml中添加此代码,将ScreenReceiver注册为:
<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文件:
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);
}
}
}