broadcastreceiver - blocking specific numbers (call and sms) in android -


i'm creating app in user can choose number block think right algorithm : when phone rings, function check number in list or not (check in database) , if there is, reject call

i found code in internet doesn't work,should call onreceive function in activity? should wrote on main activity?

here code:

public class incomingcallreceiver extends broadcastreceiver {     private itelephony telephonyservice;     private string blacklistednumber = "+458664455";      @override     public void onreceive(context context, intent intent) {         telephonymanager tm = (telephonymanager) context.getsystemservice(context.telephony_service);        try {          class c = class.forname(tm.getclass().getname());          method m = c.getdeclaredmethod("getitelephony");          m.setaccessible(true);          itelephony telephonyservice = (itelephony) m.invoke(tm);          bundle bundle = intent.getextras();          string phonenumber = bundle.getstring("incoming_number");          log.e("incoming", phonenumber);          if ((phonenumber != null) && phonenumber.equals(blacklistednumber)) {              telephonyservice.silenceringer();             telephonyservice.endcall();             log.e("hang up", phonenumber);          }         } catch (exception e) {          e.printstacktrace();        } } 

interface:

 public interface itelephony {          boolean endcall();          void answerringingcall();          void silenceringer();    } 

i added below code manifest

<receiver android:name="incomingcallreceiver" >         </receiver>  <uses-permission android:name="android.permission.read_phone_state"/>     <uses-permission android:name="android.permission.call_phone"/>    <uses-permissionandroid:name="android.permission.process_incoming_calls"/> 

did miss anything?


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -