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 700 [kskvmstatact excessive swapping observed]
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
{****************************************************************************** * * * PROJECT : EOS Digital Software Development Kit EDSDK * * NAME : EDSDKApi.pas * * * * Description: This is the ...
受影响的站点有14个,查询这14个站点近一周的历史告警,发现WUH-鸿汇城西-WEL基站12.27日出现过Sync Reference Excessive Wander告警,之后出现了Timing Sync Fault告警,表示此时该基站已处于GPS失步状态。
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 ...
前面聊的 最近在调试项目的亮屏速度,我们希望在按下power键后到亮屏这个...01-18 09:13:40.992 683 772 D SurfaceControl: Excessive delay in setPowerMode(): 743ms 01-18 09:13:45.304 683 772 D S
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. ...
Excessive levitation for the efficient loading of large-volume optical dipole traps
- fixed bug in ODF export with excessive text:p inside table:covered-table-cell - fixed bug in ODF export with language styles - fixed bug in ODF export with spaces and tab symbols - fixed bug in ODF ...
A Dielectric-Filled Waveguide Antenna Element for 3D Imaging Radar in High Temperature and Excessive Dust Conditions
过量土壤磷抑制真菌生长的机理,曹志平,,磷是一种即将耗竭的资源,但人们对此却没有充分的认识。另一方面,近几十年来磷在农业土壤中的积累速度正在加快,有可能将农业土
过量锂在合成锂离子电池正极材料0.4Li2MnO3•0.6LiNi2/3Mn1/3O2中的作用,李笑娲,顾大伟,本文采用溶胶凝胶法合成了富锂正极材料0.4Li2MnO3•0.6LiNi2/3Mn1/3O2. 通过X射线衍射(XRD),扫描电子显微镜(SEM),傅里叶...
including convolutional nets, recurrent nets, and deep reinforcement learning Learn techniques for training and scaling deep neural nets Apply practical code examples without acquiring excessive ...
In many cases BDE community are unable to employ serverspecific features, they must tolerate excessive usage of resources,reduced speed of processing data, restricted distribution of an ...
In many cases BDE community are unable to employ serverspecific features, they must tolerate excessive usage of resources,reduced speed of processing data, restricted distribution of an ...
Through a series of recent breakthroughs, deep learning has boosted the entire field of machine ...Apply practical code examples without acquiring excessive machine learning theory or algorithm details
关于AZ1117的详细英文资料 The AZ1117 is a series of low dropout ...excessive junction temperature. The AZ1117 has an adjustable version, that can provide the output voltage from 1.25V to 12V with only
Hands-On Machine Learning with Scikit-Learn and TensorFlow: Concepts, Tools, and Techniques to ...Apply practical code examples without acquiring excessive machine learning theory or algorithm details