5

我已经设置了接收android.intent.action.USER_PRESENT清单文件为每BackgroundReceiverIntent.ACTION_USER_PRESENT在蜂窝或ICS(Samsung)的设备没有收到

<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,摩托罗拉Razr)。
  • 这似乎不适用于HoneyComb(Samsung Galaxy Tab 10.1)或ICS(Samsung Galaxy Nexus)设备。
  • 根据此错误(USER_PRESENT never fires on honeycomb and ICS when keyguard is disabled),我在失败的设备上设置了键盘锁。它没有帮助。

问题:

  1. 有一些技巧,使用在Android 3.X & 4.x的这些意图的行动?
  2. 也许这是一个已知的三星问题?
  3. 或者我在这些设备上忽略了一些设备设置?
+0

这个问题意味着它可以做到:[带上任务前面android.intent.action.USER_PRESENT](http://stackoverflow.com/questions/8750854/bring-task-to-front-on-android- intent-action-user-present) – 2012-05-21 15:07:14

回答

2

有说你需要开始您的活动至少一次前,将正确地接收到所需的意图对这个答案(android app with service only)由ubuntudroid评论。

显然是在Android 3.0中引入的。

我还没有测试过这个理论,但它会解释你所看到的。

+0

我遇到了类似的行为,将由此解释。我正在自动将APK部署到设备,然后通过广播接收器与它进行交互。 (Android 5.1.1)。 USER_PRESENT操作是间歇性收到的。 – 2016-08-15 05:10:50