Are not English SMS displayed as multiple lines?

I am reading text messages in my application. Whenever an SMS message arrives, it appears in the application and is displayed.

It works in English, but when in Gujarati they are divided into several lines.

Here is my code:

final Object[] pdusObj = (Object[]) bundle.get("pdus");
                msgs = new SmsMessage[pdusObj.length];
                for (int i=0; i<msgs.length; i++) {
                    msgs[i] = SmsMessage.createFromPdu((byte[])pdusObj[i]);
                    smsReceiveTime = msgs[i].getTimestampMillis();
                    str += "SMS from " + msgs[i].getDisplayOriginatingAddress();
                    str += " :";
                    str += msgs[i].getDisplayMessageBody().toString();
                    str += "\n";
                }
+4
source share
1 answer

... but when gujarati was split into several lines

If the text message exceeds the maximum message length (which depends on the character set used), it can be split into parts and sent as a multi-page message. Something that happens in your case, and how you structured your code, it looks like you are getting several different texts.

SmsMessage onReceive(). , . , .

, , , .

@Override
public void onReceive(Context context, Intent intent) {

    String number = "unknown";
    StringBuilder message = new StringBuilder();
    long timestamp = 0;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        SmsMessage[] msgs = Telephony.Sms.Intents.getMessagesFromIntent(intent);

        number = msgs[0].getDisplayOriginatingAddress();
        timestamp = msgs[0].getTimestampMillis();

        for (int i = 0; i < msgs.length; i++) {
            message.append(msgs[i].getDisplayMessageBody());
        }
    }
    else {
        Object[] pdus = (Object[]) intent.getSerializableExtra("pdus");
        for (int i = 0; i < pdus.length; i++) {
            byte[] pdu = (byte[]) pdus[i];
            SmsMessage msg = SmsMessage.createFromPdu(pdu);

            if (i == 0) {
                number = msg.getDisplayOriginatingAddress();
                timestamp = msg.getTimestampMillis();
            }

            message.append(msg.getDisplayMessageBody());
        }
    }

    String report = String.format("SMS from %s%nMessage : %s%nSent : %s",
                                  number,
                                  message.toString(),
                                  DateFormat.getDateTimeInstance()
                                            .format(new Date(timestamp)));

    ...
}

KitKat, Telephony.Sms.Intents.getMessagesFromIntent() Intent extra, . SmsMessage, .

KitKat , . KitKat, , , .

+2

Source: https://habr.com/ru/post/1615957/


All Articles