ContentObserver is used in ContentService
ObserverNode is a capsulation of ObserverEntry to provide addObserverLocked method and so on.
./frameworks/base/core/java/android/content/ContentService.java calls registerContentObserver method to register uri and responding observer.
during this registering, a ObserverNode instance would be created, so, a ObserverEntry would be created as a observer list.
./frameworks/base/services/java/com/android/server/SystemServer.java initializes ContentService via ContentService.main.
Here is a example for using ContentObserver.
http://www.eoeandroid.com/forum.php?mod=viewthread&tid=9162&page=1
最近有个朋友问了我如何接受指定号码的短信,并且不让系统截取到通知用户。真好前端时间看天朝group,也有个朋友问了这个问题,而且通过ContentObserver方式解决了,我这里就把我实现的代码贴出来,以便需要的朋友参考。
1. public class ScreenTest extends Activity {
2.
3. class SmsContent extends ContentObserver{
4. private Cursor cursor = null;
5. public SmsContent(Handler handler) {
6. super(handler);
7. }
8.
9. /**
10. * @Description 当短信表发送改变时,调用该方法
11. * 需要两种权限
12. * android.permission.READ_SMS读取短信
13. * android.permission.WRITE_SMS写短信
14. * @Author Snake
15. * @Date 2010-1-12
16. */
17. @Override
18. public void onChange(boolean selfChange) {
19. // TODO Auto-generated method stub
20. super.onChange(selfChange);
21. //读取收件箱中指定号码的短信
22. cursor = managedQuery(Uri.parse("content://sms/inbox"),
new String[]{"_id", "address", "read"},
" address=? and read=?",
new String[]{"12345678901", "0"},
"date desc");
23.
24. if (cursor != null){
25. ContentValues values = new ContentValues();
26. values.put("read", "1"); //修改短信为已读模式
27. cursor.moveToFirst();
28. while (cursor.isLast()){
29. //更新当前未读短信状态为已读
30. getContentResolver().update(Uri.parse("content://sms/inbox"),
values,
" _id=?",
new String[]{""+cursor.getInt(0)});
31. cursor.moveToNext();
32. }
33. }
34. }
35. }
36.
37. /** Called when the activity is first created. */
38. @Override
39. public void onCreate(Bundle savedInstanceState) {
40. super.onCreate(savedInstanceState);
41. setContentView(R.layout.main);
42. SmsContent content = new SmsContent(new Handler());
43. //注册短信变化监听
44. this.getContentResolver().registerContentObserver(Uri.parse("content://sms/"), true, content);
45. }
46. }
分享到:
相关推荐
解决ORA-00700错误之内存管理和swap空间优化 在Oracle数据库中,ORA-00700错误是指内存不足或swap空间不足,导致数据库无法正常运行。解决此错误需要了解Linux系统的内存管理机制和swap空间的使用情况。...
Detection of Excessive Interrupt Disablement - a new feature which can detect a period of excessive interrupt disablement on a CPU, and create an error log record to report it. This allows you to know...
example.rs:6:1: 10:2 warning: Struct contains an excessive number (3) of bools (is_leaving_session, is_connecting, is_doing_stuff). Did you want to create a state machine?, #[warn(excessive_bool_...
Excessive 是一个用 Python 开发的 CSS 压缩工具,可拖放任意多的文件并将这些文件合并到一个文件并即时压缩。 标签:Excessive
- **含义**: E7.1报警通常表示“过速”(Excessive Velocity)。 - **触发条件**: 当驱动器检测到电机转速超过预设的最大允许速度时触发此报警。 - **可能的原因**: - 机械负载突然增加或减少。 - 伺服增益设置不当...
Firstly, the excessive use of smart-phones, especially before bedtime, poses health risks. She is depicted as using a smart-phone every night before going to sleep, which could lead to sleep disorders...
{****************************************************************************** * * * PROJECT : EOS Digital Software Development Kit EDSDK * * NAME : EDSDKApi.pas * * * * Description: This is the ...
This feature is crucial for global applications that need to cater to users from diverse linguistic backgrounds. **Extensibility:** Log4j is highly extensible, allowing developers to customize the ...
【船级社】 DNV Criteria for handling of excessive noise and vibration
the grid under: 1) excessive dc-link voltage 2) excessive ac currents and 3) loss of grid-voltage synchronization. In this paper, the control of single- and two-stage grid-connected VSIs in ...
告警名称包括"Sync Reference Excessive Wander"和"Timing Sync Fault",这些告警都是GPS失步的典型表现,直接影响了网络的同步和性能。 问题始于芜湖富贵园小区,该地区的用户报告了上行干扰,导致无法正常上网。...
configure qos profiles bandwidth UPSTREAM_10M committed-info-rate 0 assured-info-rate 0 excessive-info-rate 10000 delay-tolerance 32 ``` 此处的`UPSTREAM_10M`代表上行方向的10Mbps带宽模板。其中`...
School-based intervention for the modification of excessive absenteeism 84 A Student Team Approach to Teaching REFERENCE NOTES 1. CHECKON, S. Using Teams-Games-Tournament a t Mark Twain School. ...
- **1.2 Constructing a Dictionary Without Excessive Quoting** - **知识点:** 讲解如何高效地创建字典,避免在键或值中使用过多的引号。例如,通过使用表达式或函数结果作为键或值来减少字符串引用。 - **1.3 ...
This section lists references that may be useful for further reading or for understanding the concepts discussed in the document. It includes links to relevant specifications, articles, and other ...
### Excessive Levitation for the Efficient Loading of Large-Volume Optical Dipole Traps #### 研究背景与意义 光学偶极阱(Optical Dipole Traps, ODT)是一种利用激光束来捕获和操控原子的技术。这项技术在...
过量土壤磷抑制真菌生长的机理研究,为了解决全球因过度使用传统化学肥料导致的真菌生长抑制问题,提供了重要的理论依据和实践意义。本研究由曹志平教授领衔,在中国农业大学资源与环境科学学院生态与生态工程系完成...
A Dielectric-Filled Waveguide Antenna Element for 3D Imaging Radar in High Temperature and Excessive Dust Conditions