android.intent.action.TIME_TICK
来源:互联网 发布:fedora和centos哪个好 编辑:程序博客网 时间:2024/06/03 16:47
今天做一个显示系统时间的模块,需要监听时间的走动。于是新建了一个继承BroadcastReceiver的类:
public class TimeTickReceiver extends BroadcastReceiver {@Overridepublic void onReceive(final Context context, Intent intent) {String action = intent.getAction();if (action.equals(Intent.ACTION_TIME_TICK)) {ClockView.updateTime();} }}
想当然的在AndroidManifest.xml文件里注册监听:
<receiver android:name="com.example.weather.TimeTickReceiver" > <intent-filter> <action android:name="android.intent.action.TIME_TICK" /> </intent-filter></receiver>
结果无法监听时间的走动。查阅了Google的API,发现问题所在:
android.intent.action.TIME_TICK是一个受保护的Intent,只能被系统发出。它不能通过在AndroidManifest.xml文件中注册来接收广播,只能通过
Context.registerReceiver()明确注册。我在onCreate()方法中注册android.intent.action.TIME_TICK如下:
IntentFilter filter = new IntentFilter();filter.addAction(Intent.ACTION_TIME_TICK);receiver = new TimeTickReceiver();registerReceiver(receiver, filter);
监听时间走动成功。
0 0
- android.intent.action.TIME_TICK
- android.intent.action.TIME_TICK在清单文件里注册不起作用
- android.intent.action.TIME_TICK在清单文件里注册不起作用
- android.intent.action.TIME_TICK在清单文件里注册不起作用
- Android Intent Action 大全
- android.intent.action大全
- android.intent.action大全
- android.intent.action大全
- Android Intent Action大全
- android.intent.action.PRE_BOOT_COMPLETED
- Android Intent Action大全
- android.intent.action大全
- Android Intent Action 大全
- Android Intent Action 大全
- Android Intent Action 大全
- Android Intent Action 大全
- Android Intent action 大全
- android.intent.action大全
- Unable to execute dex: java.nio.BufferOverflowException.解决办法
- 继承时类的构造函数?
- mysql查询显示技巧
- ORA-16191的分析
- python之os.walk()与os.path.walk()
- android.intent.action.TIME_TICK
- log4j通过ActiveMQ远程记录日志设计配置
- 为JQuery绑定鼠标中键
- 【翻译】使用Sencha Touch创建基于Tizen应用程序
- 64 Android 抽屉效果 (Button)
- Java 单例模式详解
- I,P,B帧和PTS,DTS的关系<转>
- Hadoop-2.2.0 HDFS暂时不支持并发追加
- 保留2位小数点 不足补零