收到的短信字符串被拆分为两个android

时间:2019-07-02 00:13:57

标签: android broadcastreceiver sms

我有一个Android应用程序,它接收SMS并在TextView中显示它,但是文本被一分为二,而我只得到了它的最后一部分。短信为:

"Sometext SometextLBS: http://www.somewebsite.com/Page.aspx?n=4.78900,-24.03711 ,bat:69%" 

问题是L B S字母,因为一旦更改了它,字符串就不会分割吗?我尝试创建另一个变量,并将其放入if循环中定义的变量中。

@Override
public void onReceive(Context context, Intent intent) {
    //Toast.makeText(context, "SMS Received", Toast.LENGTH_SHORT).show();

    if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
        Bundle bundle = intent.getExtras();

        SmsMessage[] msgs;
        String msg_from;
        if (bundle != null) {
            try {
                Object[] pdus = (Object[]) bundle.get("pdus");

                msgs = new SmsMessage[pdus.length];


                for (int i = 0; i <msgs.length; i++) {
                    msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
                    msg_from = msgs[i].getOriginatingAddress();

                    String msgBody = msgs[i].getMessageBody();



                    msgBody=msgBody.replaceAll("Hexagonal prismeLBS: ","");

                   //String coordenatesX = msgBody.substring(msgBody.indexOf("=")+1);
                    String coordenatesX = msgBody.substring(msgBody.indexOf("=")+1);
                    String coordenatesY = msgBody.substring(msgBody.indexOf(",")+1);

                    //Toast.makeText(context, "Coordenadas"+coordenates, Toast.LENGTH_SHORT).show();


                    Bundle extras = intent.getExtras();
                    Intent intent1 = new Intent("broadCastName");
                    // Data you need to pass to activity
                    intent1.putExtra("coordx",coordenatesX);
                    intent1.putExtra("coordy",coordenatesY);

                    context.sendBroadcast(intent1);


                }

            } catch (Exception e) {
                e.printStackTrace();
            }

我想在文本视图中显示它:

"Sometext SometextLBS: http://www.somewebsite.com/Page.aspx?n=4.78900,-24.03711 ,bat:69%" I am getting "-24.03711 ,bat:69%"

0 个答案:

没有答案