Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Encode SMS message body from ContentResolver in UTF-8

I'm trying to retrieve SMS messages from device:

Cursor cursor = mContext.getContentResolver().query(Uri.parse("content://sms/inbox"), null, null, null, null);
        while (cursor.moveToNext()) {
            SmsMessage smsMessage = new SmsMessage(cursor);
            smsMessages.add(smsMessage);
        }

//.....
public SmsMessage(Cursor cursor) {
        mSender = cursor.getString(cursor.getColumnIndex("address"));
        mText = cursor.getString(cursor.getColumnIndex("body"));
        mTimestamp = cursor.getLong(cursor.getColumnIndex("date"));
    }

SMS messages are in Russian, but SMS are not UTF-8 encoded. There is no encoding settings on Samsung devices, but, for example, on Motorola Moto G it's set to "auto". So, how should I determine the encoding programmatically and encode the SMS body in UTF-8?

like image 336
artem Avatar asked Nov 02 '22 07:11

artem


1 Answers

The problem was on server-side, not on Android.

like image 80
artem Avatar answered Nov 09 '22 07:11

artem