安卓/数据库。知道为什么第一个字符"+"从电话号码中消失吗?



我使用了 Log,当我得到联系人号码并且一切都正确时,直到我从数据库中读取它们并放入列表,然后我从数字中丢失了"+"字符。

public void getNumbers(String box) {
    Uri uri = Uri.parse("content://sms/" + box);
    Cursor c = getContentResolver().query(uri, null, null, null, null);
    startManagingCursor(c);
    // Read the sms data and store it in the list
    if (c.moveToFirst()) {
        for (int i = 0; i < c.getCount(); i++) {
            SMSData sms = new SMSData();
sms.setNumber(c.getString(c.getColumnIndexOrThrow("address"))
                    .toString());
            String nr = sms.getNumber();
            Log.d("I got this:", nr);
            db.getSMSDataBySearch(nr);
            c.moveToNext();
        }
    }
    c.close();
}

还有SQLite代码:

SQLiteDatabase db = this.getWritableDatabase(); 游标光标 = db.rawQuery("插入到版本 3 (数字) 选择不存在的 "+值+" +"(从版本 3 中选择 1,其中数字 = "+值+")",空);

SMS 内容提供程序不存储格式,仅存储数字数据。

如果你想格式化它,有工具,或者你可以构建它:

Java 电话号码格式 API

最新更新