码迷,mamicode.com
首页 > 其他好文 > 详细

备份短信

时间:2015-05-05 19:14:19      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:

        /**
         * 备份短信的工具方法
         * @param context 上下文
         * @param fos 备份到哪个文件输出流里面.
         * @throws Exception
         */
        public static void backUp(Context context,FileOutputStream fos) throws Exception {//在自己的方法中使用接口
            ContentResolver resolver = context.getContentResolver();
            Uri uri = Uri.parse("content://sms/");
            XmlSerializer serializer = Xml.newSerializer();
            serializer.setOutput(fos, "utf-8");
            serializer.startDocument("utf-8", true);
            serializer.startTag(null, "smss");
            Cursor cursor = resolver.query(uri, new String[]{"address","date","type","body"}, null, null, null);
            //pd.setMax(cursor.getCount());//设置初始化的总长度
            int count = cursor.getCount(); //短信的总条数
            int total = 0;
            while(cursor.moveToNext()){
                serializer.startTag(null, "sms");
                serializer.startTag(null, "address");
                String address = cursor.getString(0);
                serializer.text(address);
                serializer.endTag(null, "address");
                serializer.startTag(null, "date");
                String date = cursor.getString(1);
                serializer.text(date);
                serializer.endTag(null, "date");
                serializer.startTag(null, "type");
                String type = cursor.getString(2);
                serializer.text(type);
                serializer.endTag(null, "type");
                serializer.startTag(null, "body");
                String body = cursor.getString(3);
                serializer.text(body);
                serializer.endTag(null, "body");
                serializer.endTag(null, "sms");
                fos.flush();
                total++;
                //pd.setProgress(total);
                
                Thread.sleep(500);
            }
            serializer.endTag(null, "smss");
            serializer.endDocument();
            fos.flush();
            fos.close();
        }

 

备份短信

标签:

原文地址:http://www.cnblogs.com/huangzx/p/4479830.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!