当前位置:   article > 正文

安卓Intent.ACTION_TIME_TICK 广播_android.intent.action.time_tick 息屏后不发送广播

android.intent.action.time_tick 息屏后不发送广播

Intent.ACTION_TIME_TICK 广播需要动态注册,不能在清单文件配置.

  1. TimeReceiver mBroadcastReceiver = new TimeReceiver();  
  2. IntentFilter intentFilter = new IntentFilter();
  3. intentFilter.addAction(Intent.ACTION_TIME_TICK);  
  4. registerReceiver(mBroadcastReceiver, intentFilter);  
在 TimeReceiver 监听广播接收。

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. public class TimeReceiver extends BroadcastReceiver {  
  2.   
  3.     @Override  
  4.     public void onReceive(Context context, Intent intent) {  
  5.         if(Intent.ACTION_TIME_TICK.equals(intent.getAction())) {  
  6.             //todo...  
  7.         }  
  8.     }  
  9. }  
在众多的Intent的action动作中,Intent.ACTION_TIME_TICK是比较特殊的一个,根据SDK描述:


Broadcast Action: The current time has changed. Sent every minute. You can not receive this through components declared in manifests, only by exlicitly registering for it withContext.registerReceiver()


意思是说这个广播动作是以每分钟一次的形式发送。但你不能通过在manifest.xml里注册的方式接收到这个广播,只能在代码里通过registerReceiver()方法注册。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/235723
推荐阅读
相关标签
  

闽ICP备14008679号