我有一个 BackgroundReceiver
设置来接收 list 文件中的 android.intent.action.USER_PRESENT
,如下所示:
<receiver android:name="com.demo.MyBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
我重写的 onReceive(Context, Intent)
方法非常简单:
@Override
public void onReceive(Context context, Intent intent)
{
if (intent != null)
{
if (Intent.ACTION_USER_PRESENT.equals(intent.getAction())
{
// wrapper for Log.d(String, String)
Dbug.log("MyBroadcastReceiver: [" + intent.getAction() + "]");
// this calls a service
serviceExample(context, intent);
}
}
}
- 这在 2.1、2.2 和 2.3 设备(HTC Desire、HTC WildFire、Motorola Razr)上完美测试。
- 这似乎不适用于 HoneyComb (Samsung Galaxy Tab 10.1) 或 ICS (Samsung Galaxy Nexus) 设备。
- 根据这个错误 (USER_PRESENT never fires on honeycomb and ICS when keyguard is disabled),我在故障设备上设置了键盘保护。它没有帮助。
问题:
- 在 Android 3.x 和 4.x 上使用这些 Intent 操作有什么技巧吗?
- 也许这是三星的一个已知问题?
- 或者我可能在这些设备上忽略了某些设备设置?
最佳答案
ubuntudroid 有评论在这个答案 ( android app with service only ) 上说你需要至少开始你的 Activity 一次才能正确接收所需的 Intent 。
显然是在 Android 3.0 中引入的。
我还没有测试这个理论,但它可以解释你所看到的。
关于android - Intent.ACTION_USER_PRESENT 未在 HoneyComb 或 ICS(三星)设备上收到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10329810/