android - Receiving in app SMS messages only from certain specified numbers -


i've set app receive sms messages , display them toast on main activity. once app has received sms abort broadcast , stop message going inbox.

currently messages phone receives carry out job , display toast when sms received specific number. know case of putting if statement receiver code i'm not sure abouts should placed.

smsreceiver.java:

public class smsreceiver extends broadcastreceiver { @override public void onreceive(context context, intent intent) {     bundle extras = intent.getextras();       if (extras ==null)         return;     //toast     toast.maketext(context, "received", toast.length_long).show();      object[] pdus = (object[]) extras.get("pdus");      (int = 0; < pdus.length; i++) {         smsmessage smessage = smsmessage.createfrompdu((byte[]) pdus[i]);         string sender = smessage.getoriginatingaddress();         string body = smessage.getmessagebody().tostring();          intent in = new intent("smsmessage.intent.main").putextra("get_msg", sender+":"+body);          context.sendbroadcast(in);         this.abortbroadcast();      } } } 

you should do:

string body=.... if(phonenumberutils.compare(sender, phonenumber)) {              abortbroadcast() something... } 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -