I want to make an android app for blocking a phone number.. But the problem := If I block a number,it rings one time the then ends the call. how can i made this without a single ring??
my code is like:--
public void blockCall(Context c, Bundle b)
{
TelephonyManager telephony = (TelephonyManager)
c.getSystemService(Context.TELEPHONY_SERVICE);
try {
Class cls = Class.forName(telephony.getClass().getName());
Method m = cls.getDeclaredMethod("getITelephony");
m.setAccessible(true);
telephonyService = (ITelephony) m.invoke(telephony);
//telephonyService.silenceRinger();
telephonyService.endCall();
} catch (Exception e) {
e.printStackTrace();
}
}
In your broadcast receiver, where you are listening for the incoming call add this method -
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
try {
Class c = Class.forName(tm.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
telephonyService = (ITelephony) m.invoke(tm);
Bundle bundle = intent.getExtras();
String phoneNumber = bundle.getString("incoming_number");
Log.d("INCOMING", phoneNumber);
if ((phoneNumber != null)) {
telephonyService.endCall();
Log.d("HANG UP", phoneNumber);
}
} catch (Exception e) {
e.printStackTrace();
}
This is working fine for me.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.