Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android短信:无法通过编程方式备份发件人名称_Android_Sqlite_Sms_Backup - Fatal编程技术网

Android短信:无法通过编程方式备份发件人名称

Android短信:无法通过编程方式备份发件人名称,android,sqlite,sms,backup,Android,Sqlite,Sms,Backup,我试图备份我设备的消息。我使用Telephony.sms备份了所有内容,如id、线程id、地址、正文、日期、人员等,但发件人姓名除外。当我打印person时,我得到了空值。但是,当我从备份中还原邮件时,它会显示匿名而不是发件人名称。我该怎么解决呢?请帮忙。这里也有类似的帖子,但没有答案 我使用下面给出的代码: private void backupSMS() { Uri mSmsinboxQueryUri = Uri.parse("content://sms"); Cursor

我试图备份我设备的消息。我使用Telephony.sms备份了所有内容,如id、线程id、地址、正文、日期、人员等,但发件人姓名除外。当我打印person时,我得到了空值。但是,当我从备份中还原邮件时,它会显示匿名而不是发件人名称。我该怎么解决呢?请帮忙。这里也有类似的帖子,但没有答案

我使用下面给出的代码:

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

Sms.PERSON是一个整数ID,用于引用联系人中的条目。这不是显示名称。@迈克,谢谢你的回复。但是,您知道哪个实体返回显示名称/发件人名称吗?请检查有关如何从该ID获取联系人的信息。但是,请注意,您的特定实现可能不使用Sms.PERSON列,在这种情况下,您必须使用电话号码获取联系人。