我正在研究android应用程序(作为我大学的最后一年项目),它备份和恢复联系人,消息,日历,通话记录等。我昨天开始研究它,直到现在我能够得到消息对话通过ContentResolver像这样:
private void MsgBackup(){
try {
Uri uri = Uri.parse("content://sms");
//Uri uri = Uri.parse("content://mms-sms/conversations/");
ContentResolver contentResolver = getContentResolver();
final String[] projection = new String[]{"*"};
Cursor SMSL = contentResolver.query(uri, projection, null, null, null);
int msgscount = SMSL.getCount();
msgs = new String[SMSL.getCount()][2];
int i = 0;
while (SMSL.moveToNext()) {
address = SMSL.getString(SMSL.getColumnIndex("address"));
body = SMSL.getString(SMSL.getColumnIndex("body"));
msgs[i][0] = address;
msgs[i][1] = body;
i++;
}
SMSL.close();
//will do something here to backups msgs array
}catch (Exception e){
e.printStackTrace();
Toast.makeText(getApplicationContext(),"Error Fetching messages, check permissions!",Toast.LENGTH_LONG).show();
}
}
我担心的是“恢复它们”。我在某处读到,没有root访问权限就无法恢复邮件。如果是这样,那么市场中的应用程序如何在没有root权限的情况下完成这项工作?