zoukankan      html  css  js  c++  java
  • android 短信监控

    class SmsContent extends ContentObserver{  
            private Cursor cursor = null;  
            public SmsContent(Handler handler) {  
                super(handler);  
            }  
           
           
              
            /** 
             * @Description 当短信表发送改变时,调用该方法  
             *              需要两种权限 
             *              android.permission.READ_SMS读取短信 
             *              android.permission.WRITE_SMS写短信 
             */ 
            @Override 
            public void onChange(boolean selfChange) {  
                // TODO Auto-generated method stub  
                super.onChange(selfChange);  
                //读取收件箱中指定号码的短信  
                cursor = managedQuery(Uri.parse("content://sms/inbox"),
                  new String[]{"_id", "address", "read"},
                  "read=?",
                  new String[]{"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();  
                    }  
                }  
            }
           
        }

  • 相关阅读:
    C#异常断电后重新启动项目出现配置未初始化错误
    TFS: 解决The build agent error
    删除TFS中的项目
    将现有项目添加到TFS中
    Typora开启行内公式
    Markdown上下标内容多于一项
    小甲鱼python基础教程飞机大战源码及素材
    Git 将本地库添加到远程仓库
    C# float与UInt16互转
    C++的重载流输出运算符
  • 原文地址:https://www.cnblogs.com/ddcddc/p/2802899.html
Copyright © 2011-2022 走看看