android11 广播 ACTION_USER_PRESENT解析

当Android设备从休眠状态唤醒,如解除锁屏后,系统会在frameworks/base/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java中的handleStartKeyguardExitAnimation方法调用sendUserPresentBroadcast,发送USER_PRESENT_INTENT广播,通知用户现在可以交互了。这是一个受保护的意图,只能由系统本身发送。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

当设备唤醒的时候系统会发送这个广播。
就是在解锁之后发送。
Broadcast Action: Sent when the user is present after device wakes up (e.g when the
keyguard is gone 。

 This is a protected intent that can only be sent
 by the system

哪里发出:

frameworks/base/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java

handleStartKeyguardExitAnimation 调用 sendUserPresentBroadcast ,
发送广播 USER_PRESENT_INTENT 。

Android中的ACTION_CONNECTION_STATE_CHANGED是一个蓝牙广播消息,用于通知应用程序蓝牙连接状态的变化。当蓝牙连接状态发生变化时,系统会发送此广播,应用程序可以通过注册BroadcastReceiver接收此广播并执行相应的操作。 使用该广播的步骤如下: 1. 在AndroidManifest.xml文件中添加以下权限: ``` <uses-permission android:name="android.permission.BLUETOOTH"/> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/> ``` 2. 注册BroadcastReceiver接收该广播: ``` IntentFilter filter = new IntentFilter(); filter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED); registerReceiver(receiver, filter); ``` 3. 在BroadcastReceiver中处理该广播: ``` private BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) { // 处理蓝牙连接状态变化 int state = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE, BluetoothAdapter.ERROR); if (state == BluetoothAdapter.STATE_CONNECTED) { // 蓝牙已连接 } else if (state == BluetoothAdapter.STATE_DISCONNECTED) { // 蓝牙已断开 } } } }; ``` 注意:该广播只能检测蓝牙连接状态的变化,无法判断蓝牙是否可用。如果需要判断蓝牙是否可用,可以使用BluetoothAdapter.getDefaultAdapter()获取BluetoothAdapter实例,并调用isEnabled()方法判断是否可用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值