該軟件支持導(dǎo)入導(dǎo)出手機(jī)通訊錄與短信,可以通過導(dǎo)出進(jìn)行備份,還可以直接閱讀導(dǎo)出信息。導(dǎo)出文件存儲在手機(jī)和SD卡里雙重保險。
下一版本設(shè)計:
1、添加備忘錄導(dǎo)入導(dǎo)出
2、優(yōu)化導(dǎo)入導(dǎo)出時間
3、添加更多導(dǎo)出選項
4、支持網(wǎng)絡(luò)化傳送導(dǎo)出文件,互相導(dǎo)入
部分代碼分享:
導(dǎo)出通訊錄
[java] view plaincopy
public void GetTongXun() throws IOException
{
ContentResolver resolver = this.getContentResolver();
Uri uri = Uri.parse("content://com.android.contacts/contacts");
Cursor cursor = resolver.query(uri, new String[]{Data._ID}, null, null, null);
File file = CreatFile(dir+"通訊錄.txt");
FileOutputStream outputStream = new FileOutputStream(file);
FileOutputStream fos = null;
fos = openFileOutput("通訊錄.txt",Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);
while(cursor.moveToNext())
{
StringBuilder buf = new StringBuilder();
int id = cursor.getInt(0);//獲得id并且在data中尋找數(shù)據(jù)
uri = Uri.parse("content://com.android.contacts/contacts/"+id+"/data"); //如果要獲得data表中某個id對應(yīng)的數(shù)據(jù),則URI為content://com.android.contacts/contacts/#/data
Cursor cursor2 = resolver.query(uri, new String[]{Data.DATA1,Data.MIMETYPE,Data.DATA10}, null,null, null); //data1存儲各個記錄的總數(shù)據(jù),mimetype存放記錄的類型,如電話、email等
String phone = null;
while(cursor2.moveToNext())
{
String data = cursor2.getString(cursor2.getColumnIndex("data1"));
if(cursor2.getString(cursor2.getColumnIndex("mimetype")).equals("vnd.android.cursor.item/name") && cursor2.getString(cursor2.getColumnIndex("data10")).equals("2") ){ //如果是名字
buf.append(data);
if (phone != null) buf.append(phone);
}
else if(cursor2.getString(cursor2.getColumnIndex("mimetype")).equals("vnd.android.cursor.item/phone_v2")){//如果是電話
phone = new String(" "+data+"\n");
}
}
String str = buf.toString();
try {
outputStream.write(str.getBytes());
fos.write(str.getBytes());
} catch (IOException ex) {}
}
try {
outputStream.close();
fos.close();
} catch (IOException ex) {}
new AlertDialog.Builder(this).setMessage("成功導(dǎo)出通訊錄!").show();
}
導(dǎo)出短信
[java] view plaincopy
public void OutDuanxin() throws IOException
{
Uri uri = Uri.parse("content://sms/");
smsContent sc = new smsContent(this,uri);
List<smsInfo> infos = sc.getSmsInfo();
List<smsInfo> realinfos = sc.getRealSmsInfo();
File file = CreatFile(dir+"短信.txt");
FileOutputStream outputStream = new FileOutputStream(file);
FileOutputStream fos = null;
fos = openFileOutput("短信.txt",Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);
File realfileFile = CreatFile(dir+"duanxin.yyqf");
FileOutputStream realoutputStream = new FileOutputStream(realfileFile);
FileOutputStream realfos = null;
realfos = openFileOutput("duanxin.yyqf",Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);
String string = new String();
String realString = new String();
for (int i=0;i<infos.size();i++)
{
string+=infos.get(i).getName();
string+="\n號碼:"+infos.get(i).getPhoneNumber();
string+="\n日期:"+infos.get(i).getDate();
string+="\n消息:"+infos.get(i).getSmsbody();
string+="\n====================================\n";
realString+=realinfos.get(i).getPhoneNumber()+"\n";
realString+=realinfos.get(i).getSmsbody()+"\n";
realString+= ".!@#$%^&*().[].yyqf\n" + realinfos.get(i).getDate()+"\n";
realString+=realinfos.get(i).getType()+"\n";
}
try {
fos.write(string.getBytes());
outputStream.write(string.getBytes());
realfos.write(realString.getBytes());
realoutputStream.write(realString.getBytes());
} catch (Exception e) {}
try {
outputStream.close();
fos.close();
realfos.close();
realoutputStream.close();
} catch (IOException ex) {}
new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_info).setMessage("成功導(dǎo)出短信!").show();
}
中文名:安卓資料導(dǎo)出備份
包名:com.yyqf.myfirstapp
MD5值:06cdebf0afbf63f41e139022726a12a3