android - "if" in method on the BroadcastReceiver service will not work -
this question has answer here:
- how compare strings in java? 23 answers
i have problem checking variables in "if". userphonenumber variable sharedpreferences , phonenumber of smsmessage.
i displaying toast both variables , same, if didn't work. problem?
my broadcastreceiver class:
public class incomingsms extends broadcastreceiver { string userphonenumber = ""; string sendernum= ""; string message= ""; final string tag="locationservice"; gpstracker gps; double latitude = 0.0; double longitude = 0.0; // object of smsmanager final smsmanager sms = smsmanager.getdefault(); public void onreceive(context context, intent intent) { sharedpreferences settings = preferencemanager.getdefaultsharedpreferences(context); userphonenumber = settings.getstring("userphonenumber", ""); log.e(tag, "userphonenumber:"+userphonenumber); int duration = toast.length_long; // retrieves map of extended data intent. final bundle bundle = intent.getextras(); try { if (bundle != null) { final object[] pdusobj = (object[]) bundle.get("pdus"); (int = 0; < pdusobj.length; i++) { smsmessage currentmessage = smsmessage.createfrompdu((byte[]) pdusobj[i]); string phonenumber = currentmessage.getdisplayoriginatingaddress().tostring(); sendernum = phonenumber; message = currentmessage.getdisplaymessagebody(); turnon(context); } // end loop } // bundle null } catch (exception e) { log.e("smsreceiver", "exception smsreceiver" +e); } log.i("smsreceiver", "sendernum: " + sendernum + "userphonenumber: "+ userphonenumber + "; message: " + message); } public void turnon (context context){ intent = new intent(context, myservice.class); gps = new gpstracker(context); toast.maketext(context,"method turnon!\nsendernum: "+sendernum + "\n userphonenumber: " + userphonenumber, toast.length_long).show(); if (sendernum == userphonenumber) { toast.maketext(context,"works in if", toast.length_long).show(); if(gps.cangetlocation()){ latitude = gps.getlatitude(); longitude = gps.getlongitude(); i.putextra("latitude", latitude); i.putextra("longitude", longitude); context.startservice(i); }else { gps.showsettingsalert(); } } gps.stopusinggps(); }
sendernum it's string means if should be:
if (sendernum.equals(userphonenumber))
Comments
Post a Comment