首页 > 系统 > Android > 正文

android监听手机解锁

2019-11-06 10:00:27
字体:
来源:转载
供稿:网友

手机解锁,系统会发送广播,只要监听该广播就可以做想做的事情了,非常简单。

配置文件中注册:

<receiver android:name="com.example.hidetest.screen.ScreenReceiver">            <intent-filter>                 <action android:name="android.intent.action.USER_PRESENT" />              </intent-filter> </receiver>

广播类:

public class ScreenReceiver extends BroadcastReceiver{@Overridepublic void onReceive(Context context, Intent intent) {//做想做的事 }}

屏灭和屏亮一般会和解锁一起使用,但是需要注意的是,屏亮和屏灭的广播,只能动态注册。

屏亮:

action:Intent.ACTION_SCREEN_ON

      action:Intent.ACTION_SCREEN_OFF


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表