android - string doesnt set off if condition but log output suggests it should -


so im making app uses sms send data between 2 devices , trying 1 automaticly respond other. string getmessagebody() returning isnt setting of if statment send automatic message tho log output "(test)" seems match condition. have added text either side of string in log message check whitespace. in advance.

the code sending message received.

sendsms(inputnum.gettext().tostring(),"test"); 

the receiver code

public void onreceive(context context, intent intent)         {             bundle bundle = intent.getextras();             smsmessage[] msgs = null;             if(bundle != null)             {                 object[]pdus = (object[]) bundle.get("pdus");                 msgs = new smsmessage[pdus.length];                 for(int = 0;i < msgs.length;i++)                 {                     msgs[i] = smsmessage.createfrompdu((byte[])pdus[i]);                     originnumber = msgs[i].getoriginatingaddress();                     messages = msgs[i].getmessagebody();                     log.e("received text", messages);                  }                 if(messages == "test")                     sendsms(originnumber, "auto send");                 else                     log.e("else text", "("+messages+")");             } 

   if(messages == "test") 

string comparison in java need equals method. == compare address of message address of "test". since differente string object result false. change in:

   if(messages.equals("test")) 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -