我尝试备份设备的消息。我使用Telephony.sms备份了id,线程ID,地址,正文,日期,人等所有内容,除了发件人姓名。当我打印人时,我得到了null。但是,当我从备份中恢复邮件时,它会显示“匿名”而不是发件人姓名。我该怎么解决?请帮助。这里也有类似的帖子,但没有答案。 android sms sender name returns null
我使用下面给出的代码:
private void backupSMS() {
Uri mSmsinboxQueryUri = Uri.parse("content://sms");
Cursor cursor1 = getContentResolver().query(mSmsinboxQueryUri, null,
null, null, null);
// startManagingCursor(cursor1);
// String[] columns = new String[] { "_id", "thread_id", "address",
// "person", "date", "body", "type" };
ArrayList<SMS> smsList = new ArrayList<SMS>();
int _id = cursor1.getColumnIndex(Telephony.Sms._ID);
int thread_id = cursor1.getColumnIndex(Telephony.Sms.THREAD_ID);
int address = cursor1.getColumnIndex(Telephony.Sms.ADDRESS);
int body = cursor1.getColumnIndex(Telephony.Sms.BODY);
int date = cursor1.getColumnIndex(Telephony.Sms.DATE);
int date_sent = cursor1.getColumnIndex(Telephony.Sms.DATE_SENT);
int person = cursor1.getColumnIndex(Telephony.Sms.PERSON);
int protocol = cursor1.getColumnIndex(Telephony.Sms.PROTOCOL);
int read = cursor1.getColumnIndex(Telephony.Sms.READ);
int service_center = cursor1
.getColumnIndex(Telephony.Sms.SERVICE_CENTER);
int status = cursor1.getColumnIndex(Telephony.Sms.STATUS);
int subject = cursor1.getColumnIndex(Telephony.Sms.SUBJECT);
int type = cursor1.getColumnIndex(Telephony.Sms.TYPE);
if (cursor1.getCount() > 0) {
String count = Integer.toString(cursor1.getCount());
Log.d("Count", count);
while (cursor1.moveToNext()) {
SMS sms = new SMS();
sms.setId(cursor1.getInt(_id));
sms.setThread_id(cursor1.getInt(thread_id));
sms.setAdress(cursor1.getString(address));
sms.setBody(cursor1.getString(body));
sms.setDate(cursor1.getLong(date));
sms.setSDate(cursor1.getLong(date_sent));
sms.setPerson(cursor1.getString(person));
sms.setProtocol(cursor1.getInt(protocol));
sms.setRead(cursor1.getInt(read));
sms.setService_center(cursor1.getString(service_center));
sms.setStatus(cursor1.getInt(status));
sms.setSubject(cursor1.getString(subject));
sms.setType(cursor1.getInt(type));
smsList.add(sms);
}
}
db = new SMSDatabase(this);
if (db.addSMS(smsList)) {
Toast.makeText(getApplicationContext(),
cursor1.getCount() + " SMS backedup succesfully",
Toast.LENGTH_SHORT).show();
}
}