バックアップメッセージ

4917 ワード

        /**
         *  
         * @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();
        }