android - Send sms after call rejection - being sent multiple times -


i want send sms after reject incoming call. app sending sms problem is sending twice. unable figure out problem is.

below code used.

public class callbarring extends broadcastreceiver {     private string number;      @override     public void onreceive(context context, intent intent)      {         // if, received action not type of "phone_state", ignore          if (!intent.getaction().equals("android.intent.action.phone_state"))               return;          // else, try action          else           {              // fetch number of incoming call              number = intent.getstringextra(telephonymanager.extra_incoming_number);               // check, whether member of "black listed" phone numbers stored in database             if(mainactivity.blocklist.contains(new blacklist(number)))              {                  // if yes, invoke method                  disconnectphoneitelephony(context);                  sendsms(context);                //  return;              }else{                  disconnectphoneitelephony(context);                  sendsms(context);               }          }       }      public void sendsms(context context) {          try{         string message = sharedprefactivity.commonmethod.getprefsdata(context, sharedprefactivity.constants.textmessage, "");          intent intent=new intent(context,callbarring.class);           pendingintent pi=pendingintent.getactivity(context, 0, intent,0);           smsmanager sms=smsmanager.getdefault();           sms.sendtextmessage(number, null, message, pi,null);         toast.maketext(context, "sms sent", toast.length_long).show();          } catch (exception e)         {             toast.maketext(context, "sms faild, please try again later!", toast.length_long).show();             e.printstacktrace();         }           }      // method disconnect phone automatically , programmatically      // keep method       @suppresswarnings({ "rawtypes", "unchecked" })      private void disconnectphoneitelephony(context context)       {          itelephony telephonyservice;          telephonymanager telephony = (telephonymanager)           context.getsystemservice(context.telephony_service);            try           {              class c = class.forname(telephony.getclass().getname());              method m = c.getdeclaredmethod("getitelephony");              m.setaccessible(true);              telephonyservice = (itelephony) m.invoke(telephony);              telephonyservice.endcall();          }           catch (exception e)           {              e.printstacktrace();          }      } } 

try this:

// check, whether a.   member of "black listed" phone.   numbers stored in database             if(mainactivity.blocklist.contains(new blacklist(number)))      {          // if yes, invoke method                  disconnectphoneitelephony(context);          sendsms(context);        //  return;      }else{                  disconnectphoneitelephony(context);          sendsms(context);       } 

this

// check, whether a.       member of "black listed" phone.       numbers stored in database                 if(mainactivity.blocklist.contains(new blacklist(number)))      {          // if yes, invoke method                  disconnectphoneitelephony(context); sendsms(context)          }  

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -