75

I want to block calls from few numbers, for that I want to write a app of my own. So what are the APIs which I should be using?

Basically I want to get notified when a call comes, i want to compare numbers if it is what i want to block, i want to cut the call or mute it or if possible mute it and record it.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Anurag Uniyal
  • 85,954
  • 40
  • 175
  • 219

5 Answers5

65

OMG!!! YES, WE CAN DO THAT!!! I was going to kill myself after severe 24 hours of investigating and discovering... But I've found "fresh" solution!

// "cheat" with Java reflection to gain access to TelephonyManager's
// ITelephony getter
Class c = Class.forName(tm.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
telephonyService = (ITelephony)m.invoke(tm);

all all all of hundreds of people who wants to develop their call-control software visit this start point

there is a project. and there are important comments (and credits)

briefly: copy aidl file, add permissions to manifest, copy-paste source for telephony management )))

Some more info for you. AT commands you can send only if you are rooted. Than you can kill system process and send commands but you will need a reboot to allow your phone to receive and send calls =)))

I'm very hapy =) Now my Shake2MuteCall will get an update !

Guido
  • 46,642
  • 28
  • 120
  • 174
foryou
  • 1,799
  • 2
  • 11
  • 4
  • 6
    Even if that works, it seems a little risky to me. Your application could be broken without notice whenever the internal API changes. – Guido Aug 11 '10 at 06:53
  • 4
    That's because Google Code has been shut down. Exactly why people warn of link rot here. Post anything relevant in your posts. You may think Google is one source you can trust to remain up forever, but as you can see, even their links get broken. – o_O Aug 17 '12 at 18:36
  • Is there a way to send calls to voice mail? – powder366 Feb 26 '14 at 18:06
  • getting NoSuchMethodException at Method m = c.getDeclaredMethod("getITelephony");.. How to avoid it???? – Uniruddh Mar 26 '14 at 12:42
  • what is ITelephony in the last line?? please reply I'm not able to import it – Shirish Herwade Mar 10 '16 at 11:02
4

It is possible and you don't need to code it on your own.

Just set the ringer volume to zero and vibration to none if incomingNumber equals an empty string. Thats it ...

Its just done for you with the application Nostalk from Android Market. Just give it a try ...

  • 8
    Question is not about any such app, it is how to block incoming number programatically + in your solution how will I know what is the number? – Anurag Uniyal Sep 20 '09 at 11:28
  • 2
    It's not that hard ... if you look inside the SDK reference you will see that there is an onCallStateChangeListener() wich has to be registered in your app. Once done it will deliver you the callState wich could be one of IDLE, RINGING or OFF_HOOK. Besides that the listener will deliver you the incomingNumber ... That is the point where your action comes in place. Unfortionally the SDK won't really give you an option to drop a call, these functions are NOT public available, they are hidden in a way that there is no way to access them. –  Sep 21 '09 at 12:00
4

In android-N, this feature is included in it. check Number-blocking update for android N

Android N now supports number-blocking in the platform and provides a framework API to let service providers maintain a blocked-number list. The default SMS app, the default phone app, and provider apps can read from and write to the blocked-number list. The list is not accessible to other app.

advantage of are:

  1. Numbers blocked on calls are also blocked on texts
  2. Blocked numbers can persist across resets and devices through the Backup & Restore feature
  3. Multiple apps can use the same blocked numbers list

For more information, see android.provider.BlockedNumberContract

Update an existing project.

To compile your app against the Android N platform, you need to use the Java 8 Developer Kit (JDK 8), and in order to use some tools with Android Studio 2.1, you need to install the Java 8 Runtime Environment (JRE 8).

Open the build.gradle file for your module and update the values as follows:

android {
  compileSdkVersion 'android-N'
  buildToolsVersion 24.0.0 rc1
  ...

  defaultConfig {
     minSdkVersion 'N'
     targetSdkVersion 'N'
     ...
  }
  ...
}
Amit Vaghela
  • 22,772
  • 22
  • 86
  • 142
  • Links of this post are not valid! Both of them get 404 not found! – hadilq Dec 26 '16 at 10:18
  • As of this comment you can view the links here: https://developer.android.com/about/versions/nougat/android-7.0.html#number-blocking https://developer.android.com/reference/android/provider/BlockedNumberContract.html Also found the call screening to be relevant: https://developer.android.com/about/versions/nougat/android-7.0.html#call_screening – Joel McBeth Dec 27 '17 at 21:16
3

You could just re-direct specific numbers in your contacts to your voice-mail. That's already supported.

Otherwise I guess the documentation for 'Contacts' would be a good place to start looking.

Cogsy
  • 5,584
  • 4
  • 35
  • 47
0

You can do it by listening to phone call events . You do it by having a BroadcastReceiver to PHONE_STATE and to NEW_OUTGOING_CALL. You find there what is the phone number.

Then when you decide to end the call, this is a bit tricky, because only from Android P it's guaranteed to work. Check here.

android developer
  • 114,585
  • 152
  • 739
  • 1,270