我有一个 BackgroundReceiver
设置为接收 android.intent.action.USER_ preSENT
的清单文件按:
<接收器的Android版本:NAME =com.demo.MyBroadcastReceiver>
<意向滤光器>
<作用机器人:名称=android.intent.action.USER_ preSENT/>
&所述; /意图滤光器>
< /接收器>
我重写的onReceive(上下文,意图)
的方法很简单:
@覆盖
公共无效的onReceive(上下文的背景下,意图意图)
{
如果(意向!= NULL)
{
如果(Intent.ACTION_USER_ preSENT.equals(intent.getAction())
{
//包装Log.d(字符串,字符串)
Dbug.log(MyBroadcastReceiver:[+ intent.getAction()+]);
//这个调用服务
serviceExample(背景下,意图);
}
}
}
这完全测试的2.1,2.2和放大器; 2.3设备(HTC渴望,HTC野火,摩托罗拉RAZR)。 这似乎并没有工作在蜂窝(三星Galaxy Tab 10.1)或ICS(三星Galaxy Nexus的)设备。 按照这个bug( USER_ preSENT永远大火在蜂窝和ICS时,键盘锁定禁用),我设置的故障设备的键盘锁。它并没有帮助。
问题:
有一些技巧,使用在Android 3.X及放这些意图的行动; 4.x的? 也许这是一个已知的问题,三星? 或者,也许有一些设备的设置我都忽视了这些设备? 解决方案目前在这个答案评论由 ubuntudroid (与服务只的Android应用程序)说,你需要开始你的活动至少一次,然后才能正确地接收到所需的意图
显然,在的Android 3.0推出。
我没有测试过这种理论还没有,但它可以解释你所看到的。
I have a BackgroundReceiver
set up to receive the android.intent.action.USER_PRESENT
in the manifest file as per:
<receiver android:name="com.demo.MyBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
My overridden onReceive(Context, Intent)
method is very simple:
@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);
}
}
}
This tested perfectly on 2.1, 2.2 & 2.3 devices (HTC Desire, HTC WildFire, Motorola Razr). This does not seem to work on HoneyComb (Samsung Galaxy Tab 10.1) or ICS (Samsung Galaxy Nexus) devices. As per this bug (USER_PRESENT never fires on honeycomb and ICS when keyguard is disabled), I set the keyguard on the failing devices. It did not help.
Questions:
Is there some trick to using these intent actions on Android 3.x & 4.x? Perhaps this is a known Samsung issue? Or perhaps there is some device setting I have neglected on these devices?解决方案
There is a comment by ubuntudroid on this answer (android app with service only) that says you need to start your activity at least once before it will correctly receive the required intents.
Apparently introduced in Android 3.0.
I have not tested this theory yet, but it would explain what you are seeing.
上一篇:从设置阅读字体大小字体大小
下一篇:Android的ACTION_IMAGE_CAPTURE有时不叫onActivityResult不叫、ACTION_IM、Android、onActivityResult