以下是别人使用 ContentObserver 来监听短信数据库变化来实现的。
- public class ScreenTest extends Activity {
-
- class SmsContent extends ContentObserver{
-
- private Cursor cursor = null;
-
- public SmsContent(Handler handler) {
-
- super(handler);
-
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- @Override
-
- public void onChange(boolean selfChange) {
-
-
-
- super.onChange(selfChange);
-
-
-
- cursor = managedQuery(Uri.parse("content://sms/inbox"), new String[]{"_id", "address", "read"}, " address=? and read=?", new String[]{"12345678901", "0"}, "date desc");
-
- if (cursor != null){
-
- ContentValues values = new ContentValues();
-
- values.put("read", "1");
-
- cursor.moveToFirst();
-
- while (cursor.isLast()){
-
-
-
- getContentResolver().update(Uri.parse("content://sms/inbox"), values, " _id=?", new String[]{""+cursor.getInt(0)});
-
- cursor.moveToNext();
-
- }
-
- }
-
- }
-
- }
-
-
-
- @Override
-
- public void onCreate(Bundle savedInstanceState) {
-
- super.onCreate(savedInstanceState);
-
- setContentView(R.layout.main);
-
- SmsContent content = new SmsContent(new Handler());
-
-
-
- this.getContentResolver().registerContentObserver(Uri.parse("content://sms/"),
-
-
- true, content);
-
- }
-
- }
-
- public class ScreenTest extends Activity {
-
- class SmsContent extends ContentObserver{
-
- private Cursor cursor = null;
-
- public SmsContent(Handler handler) {
-
- super(handler);
-
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- @Override
-
- public void onChange(boolean selfChange) {
-
-
-
- super.onChange(selfChange);
-
-
-
- cursor = managedQuery(Uri.parse("content://sms/inbox"), new String[]{"_id", "address", "read"}, " address=? and read=?", new String[]{"12345678901", "0"}, "date desc");
-
- if (cursor != null){
-
- ContentValues values = new ContentValues();
-
- values.put("read", "1");
-
- cursor.moveToFirst();
-
- while (cursor.isLast()){
-
-
-
- getContentResolver().update(Uri.parse("content://sms/inbox"), values, " _id=?", new String[]{""+cursor.getInt(0)});
-
- cursor.moveToNext();
-
- }
-
- }
-
- }
-
- }
-
-
-
- @Override
-
- public void onCreate(Bundle savedInstanceState) {
-
- super.onCreate(savedInstanceState);
-
- setContentView(R.layout.main);
-
- SmsContent content = new SmsContent(new Handler());
-
-
-
- this.getContentResolver().registerContentObserver(Uri.parse("content://sms/"), true, content);
-
- }
-
- }
如何截取指定号码的短信,并且不让系统截取到通知用户,布布扣,bubuko.com
如何截取指定号码的短信,并且不让系统截取到通知用户
原文:http://www.cnblogs.com/lining301/p/3617681.html