Friday, September 3, 2010

Call Control in Android

This tutorial is for those who want to control Phone Call in Android OS. Programmatic approach to Accept or Reject call without user intervention.
Kindly note, this approach uses Java Reflection to call methods of an internal class of Android Telephony Framework and might not work with all versions of Android OS. The core concept has been explained in this open code
1st thing 1st, Give the permission...
You need to define 3 User Permissions to handle call related functionality- (due to limitation of Blogger XML Tag marking has been replaced with “[“ and “]”)
[uses-permission android:name="android.permission.READ_PHONE_STATE"/]
[uses-permission android:name="android.permission.MODIFY_PHONE_STATE"/] (For answerRingingCall() method)
[uses-permission android:name="android.permission.CALL_PHONE"/] (For endCall() method)
Define a Receiver...
Create a Receiver which accepts broadcasts with intent action android.intent.action.PHONE_STATE, define following in the Manifest,
 [receiver android:name=".PhoneCall"]
        [intent-filter]
            [action android:name="android.intent.action.PHONE_STATE"/]  
        [/intent-filter]
[/receiver]

Handle Broadcast inside your Receiver...
Override onReceive() method and using Java Reflection try to get the Instance of one of hidden class of Android Telephony Framework- com.android.internal.telephony.ITelephony
ITelephony defines a set of useful methods to control the Call state, which are hidden from general Android API.
private void getTeleService() {
        TelephonyManager tm = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);
        try {
            // Java reflection to gain access to TelephonyManager's
            // ITelephony getter
            Log.v(TAG, "Get getTeleService...");
            Class c = Class.forName(tm.getClass().getName());
            Method m = c.getDeclaredMethod("getITelephony");
            m.setAccessible(true);
            com.android.internal.telephony.ITelephony telephonyService = (ITelephony) m.invoke(tm);
        } catch (Exception e) {
            e.printStackTrace();
            Log.e(TAG,
                    "FATAL ERROR: could not connect to telephony subsystem");
            Log.e(TAG, "Exception object: " + e);
        }
}
Now, you can use telephonyService (which is an instance of com.android.internal.telephony.ITelephony) to "Accept"/"Reject" call and many other operations.
// Accept Call
telephonyService.answerRingingCall();
// Reject Call
telephonyService.endCall();

Sample Flow for Call Barring Application
1.     Define a set of numbers to be blocked-
String[] blockedNumbers = {"+919811284018", "+919811284012"};
2.     Read incoming phone number
String incommingNumber;
@Override
public void onReceive(Context context, Intent intent) {
Bundle b = intent.getExtras();
incommingNumber = b.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
// Additional Step
// Check whether this number matches with your defined Block List
// If yes, Reject the Call
}
3.     Reject this Call
telephonyService.endCall();

Hope it helps! 
I have developed one Widget PhoneAway and it uses the above explained concept. Feel free to download its source (through SVN) and APK.

Update: 
To mute an ongoing call, you can use com.android.internal.telephony.ITelephony.setMute(boolean ). You need to make sure the Call State is CALL_STATE_OFFHOOK
e.g.
continuing above code base-
if(tm.getCallState() == TelephonyManager.CALL_STATE_OFFHOOK){
  // mute the call
  telephonyService.setMute(true);
}


Kindly note: I couldn't test properly the above code. Please let me know if the Mute functionality works.

146 comments:

  1. Hi there,

    How to mute an incoming call by clicking a mute button which i placed on screen when i get an incoming call?

    How to do it programatically?

    Please, if you can, write on your blog.

    Thanks,
    Mark

    ReplyDelete
  2. Mark,
    i'll definitely give a try and let you know.
    -Prasanta

    ReplyDelete
  3. Hi there,

    How to do outgoing call barring in android programatically?

    Please, if you can, write on your blog.

    Thanks,
    David

    ReplyDelete
  4. Hi,

    With which version of OS have you tested the solution ?

    Anyone can please post any results ?

    Thanks,
    Karlos

    ReplyDelete
  5. Hi Karlos,
    this sample is tested with Android 2.1. Are you facing problem ?

    Thanks,
    Prasanta

    ReplyDelete
  6. Good stuff, I've been looking for info on how to do this through reflection. Have you played around with placing a call on hold?

    ReplyDelete
  7. Prasanta,

    am in error on that line.

    com.android.internal.telephony.ITelephony telephonyService = (ITelephony) m.invoke(tm);

    The Andriod not find the class ITelephony

    This class does not exist in the SDK 2.1!

    ReplyDelete
  8. Jaison,
    you need to have an internal framework JAR file to run this-
    framework_intermediates-classes-full-debug.jar
    This JAR you will get when you do complete build of Android OS.

    ReplyDelete
  9. prasanta..,

    Can u tell me how to get jar u have specified to
    access , can u please help me ?
    com.android.internal.telephony.ITelephony telephonyService = (ITelephony) m.invoke(tm);

    ReplyDelete
  10. You can get the JAR from here-FW_JAR


    You need to use this as Eclipse User Library.

    ReplyDelete
  11. hi Prasanta ,

    I copied ITelephony.aidl from google open source , and i h got how to reject and accept calls . Thank u much for ur input .
    I need one more help i.e; can u please tell me how to send mms directly from code , i mean with no further user input.

    Thank u

    ReplyDelete
    Replies
    1. Can you please tell me how you done to reject call?

      can you share code at umer.tech5@gmail.com

      Delete
  12. i cannot understand,i am beginer,could you give me this example thank you

    ReplyDelete
  13. Hi,

    I having the same issue.
    Where did you put the file "ITelephony.aidl" ?
    how do i use the .jar file in eclipse ?
    When i go to Project/Properties/Libraries - I can see under android.jar/access rules:
    Forbidden: com/android/internal/**

    any idea ?

    Thanks,

    ReplyDelete
  14. Hi,
    if you are using the attached JAR, you need to include that as User Library in Eclipse-
    Your Project Folder->Build Path->Add Libraraies...->User Library

    Hope it helps.
    -Prasanta

    ReplyDelete
  15. Hi Pransanta,

    Thanks for your reply.
    Adding the jar caused to memory heap error.
    How can i add just the ITelephony.aidl

    ReplyDelete
  16. To use ITelePhony.aidl
    - copy and past ITelePhony.aidl under com.android.internal.telephony package of your Eclipse Project

    - It should generate automatically ITelephony.java under gen folder.

    hope it helps.

    ReplyDelete
  17. hi prasanta,

    Conversion to Dalvik format failed: Unable to execute dex: null

    i got this problem after attach that JAR file. i clear my work space and rebuild it then also i got the same problem. can you please help me.

    ReplyDelete
    Replies
    1. Modify the -XmsAm and -XmxBm paremeters in eclipse.ini so that they are large enough. The default is -Xms40m -Xmx384m. Try changing them both to -Xms512m -Xmx512m and restart eclipse to see if that helps. If not, continue to increase the values and restart eclipse until either one of two things happens:

      Your build completes.
      Eclipse won't restart because you don't have enough memory.

      Refer link: http://stackoverflow.com/questions/5943712/conversion-to-dalvik-format-failed-unable-to-execute-dex-java-heap-space

      Delete
  18. You need to include the JAR as "User Library". In Eclipse-
    Your Project Folder->Build Path->Add Libraraies...->User Library

    ReplyDelete
  19. Prasanta thanks for replying.

    I did everything you said and bugs out, but when run the app, get the following exception:


    10-16 23:26:08.375: VERBOSE/TEST CALL(1700): Get getTeleService...
    10-16 23:26:08.405: WARN/System.err(1700): java.lang.NoSuchMethodException: getlTelephoney

    ReplyDelete
  20. Awesome post !! very informatory and helpful . Everything worked except telephonyService.setMute(true); .

    thanks a lot for this

    ReplyDelete
  21. Hai prasanta , i used ur code , to detect phone call, in ddms am getting , prasanta-phone call as tag



    10-19 10:32:23.303: VERBOSE/Prasanta-PhoneCall(253): Incoming Call BroadCast received...
    10-19 10:32:23.303: VERBOSE/Prasanta-PhoneCall(253): Intent: [android.intent.action.PHONE_STATE]
    10-19 10:32:23.303: VERBOSE/Prasanta-PhoneCall(253): Bundle: Bundle[mParcelledData.dataSize=48]
    10-19 10:32:23.303: VERBOSE/Prasanta-PhoneCall(253): Phone Number: null
    10-19 10:32:23.303: VERBOSE/Prasanta-PhoneCall(253): Phone State: OFFHOOK
    10-19 10:32:23.303: VERBOSE/Prasanta-PhoneCall(253): Get getTeleService...
    10-19 10:32:23.303: VERBOSE/Prasanta-PhoneCall(253): answerCall...
    10-19 10:32:23.303: VERBOSE/Prasanta-PhoneCall(253): silenceRinger... Over


    I want to change that ? i mean ddms message ? how can i change that in my code ?

    Thank u,
    Sai srinivas

    ReplyDelete
  22. @ Jaison:
    pls try with the ITelePhony.aidl

    @ Srinivas:
    you need to write your own Application following the steps that i have explained.

    ReplyDelete
  23. But am not using single line of code of yours. still am getting debugging messages with name as tag. how to avoid it ?

    ReplyDelete
  24. Boss.... Really very good stuff... its very helpul with my telephony app.... Keep it up...

    ReplyDelete
  25. Hi, great job...The telephonyService.answerRingingCall() works for me but not the telephonyService.endCall(). Is there any other permissions that need to be set or anything else that needs to be done? Thanks!

    ReplyDelete
  26. Hi Charlie,
    thanks. I forgot to mention, for endCall() you need to add a User Permission-
    android.permission.CALL_PHONE

    hope it helps.

    ReplyDelete
  27. hiiiiiii prasanta can u help me in a project of android app Tablet Application.....

    i have some problems in it
    can u help me in this concern
    whats ur id
    where i can mail u application apk file

    Regards
    Tushar SAHNI

    ReplyDelete
  28. Thanks Prasanta, the android.permission.CALL_PHONE worked for thetelephonyService.endCall().

    Thanks again!!!

    ReplyDelete
    Replies
    1. Could you please share the source code with me.
      Thanks.

      Delete
  29. Many thanks for amazing post.
    Keep up the good work...

    ReplyDelete
  30. hi Prasanta,
    I am android beginner. I need exact usage of this ITelephony.aidl or ITelephony.jar. i totally confused.
    Awaiting for ur reply at earliest.

    ReplyDelete
  31. Great post Prasanta !
    It's working very well in my application.
    I've tested with the new Android 2.3 emulator and I get an security exception about android.permission.MODIFY_PHONE_STATE.
    Android is saying that this permission is missing for the current user or process.
    I've checked it my manifest and it's in there.

    Is it working for you with Android 2.3 ?

    ReplyDelete
  32. Hi,

    I haven't yet tested this with Android 2.3
    Tested versions 2.1, 2.2

    BR,
    Prasanta

    ReplyDelete
  33. Great post Prasanta, quick question, this all runs fine in the emulators, however when I test them on the phone it only works after I restart the phone. Are you aware of this being a requirement? Thanks for the post again.

    ReplyDelete
  34. Hi.. I have added the android.permission.CALL_PHONE. but its not working... Please help me...

    ReplyDelete
  35. pls be more specific and let me know the actual problem you are facing.

    ReplyDelete
  36. its not giving any error for "com.android.internal.telephony.ITelephony telephonyService = (ITelephony) m.invoke(tm);"
    but not implementing this line...

    ReplyDelete
  37. pls check my implementation-
    http://prasanta-paul.blogspot.com/2010/12/phone-away-widget.html
    and make sure you are following everything correctly.

    hope it helps.

    ReplyDelete
  38. Thanks prasanta....

    ReplyDelete
  39. Hi..ur post is great but am having an issue.
    As u said I saved my block numbers in an array and compared with number and used endcall method. But It doing nothing...
    Please help..

    ReplyDelete
  40. Hi,

    you can look into the code base of
    http://prasanta-paul.blogspot.com/2010/12/phone-away-widget.html

    This might help you.

    Cheers,
    Prasanta

    ReplyDelete
  41. I tested on Android 2.1, 2.2, 2.3. Worked perfectly on the first two, but the last one. Any one had successfully tested on Android 2.3?

    ReplyDelete
  42. endCall seems will kill not only the incoming call but exists call (if any) too, any good way to reject only the ringing call ?

    ReplyDelete
  43. Hi Prasanta,

    I'm an android beginner. This stuff meade me learnt alot. can you please suggest me how to intercept an incoming and outgoing call.

    ReplyDelete
  44. hi,
    Im trying to develop an app which automatically receives an incoming call,plays a pre-recorded message pretending the caller to pass his message and the app should alert the user and should be able to play the phone conversation.............
    can i do this???
    how to go about?

    ReplyDelete
  45. send me the entire sample code for receiving an incoming call???
    only the .java file

    Thanks in advance

    ReplyDelete
  46. how can I use com.android.internal.telephony.ITelephony
    Its not available in the SDK.

    ReplyDelete
  47. Hi,
    Amazing post. I tried the app and its working but before blocking for a fraction of second call screen used to come. I don't want that also. Is there any way to acheive this.
    Thanks in advance :)

    ReplyDelete
  48. Hi,
    you can get ITelephony from-
    http://groups.google.com/group/blogresources/web/ITelephony.aidl

    Or you can try my PhoneAway widget source code-
    http://prasanta-paul.blogspot.com/2010/12/phone-away-widget.html

    Thanks,
    prasanta

    ReplyDelete
    Replies
    1. Hey Prasanta,
      did u find a way to handle conference call??
      just as you handled the ITelephony interface class via AIDL I've just tried the same with the com.android.internal.telephony.Phone interface because this one includes the void conference() (for gsm mode). I need to get access to it but unlike the ITelephony class (TelephonyManager has getITelephony() ) i can't find a getPhone() anywhere... maybe another way to implement??? that would save my future as android developer :))) so I'd be very grateful to you if you'd give me a hint.
      Also if you knew any way to start a conference while having an active call and a call on hold without user interaction on the phone (maybe with bluetooth headset or some other device) - this would also be helpful in some way.
      with kind regards

      bossoss

      Delete
    2. I do not get your files
      guide me how to take away your

      Delete
    3. Hi BossOss,

      I have also tried to make use of com.android.internal.telephony.Phone interface to make conference call but it is not working.
      If you could share if you get any solution or any other way to achieve this , i would be great full...

      Thanks,
      chandu

      Delete
  49. Hi Sumit,

    thanks. When call comes, broadcast is sent and as we are handling it, at the same time PhoneApp (Android Call App) also does the same. So, if you want to block the complete broadcast, probably this need to be "Ordered Broadcast".
    I'm not sure whether the Call Broadcast is ordered or not.

    Thanks,
    Prasanta

    ReplyDelete
  50. First thank you very much for this blog, I am a novice programmer android and helping me a lot. Second sorry for my English is pretty bad ...

    My question is whether this example of call control, it would be possible to remove missed call notification Automatic android.

    Thank you very much

    ReplyDelete
  51. Great post, Thanks!

    I'm looking for the following solution:
    Keep the incoming call ringing in the background and keep the running application running (with user permission of course..)

    Does anyone has an idea?

    Thanks,
    Voper

    ReplyDelete
  52. Thanks,
    very good job.
    Has somebody an idea how to check if a call is established.

    I have tried a lot without success.

    Thanks
    Chris

    ReplyDelete
  53. Hey!

    I'm sorry, but I have read your post, and I've read all comments on here, and searched Google, and tried many different approaches, but I cannot get my project to include ITelephony.aidl.

    I'm fairly new to java, so I'm sorry if I'm missing something simple, but I may need you to explain it in simpler terms for me.

    I have tried the jar, and copying the aidl, etc. I followed your link to your Phone Away Widget, but didn't see any source code available.

    Thank you, I appreciate it!
    Paul

    ReplyDelete
  54. Hey, nevermind, I figured it out finally. All I did was create a new blank java file in my project that I'm working on, and called it ITelephony.java. Then I copied and pasted the code from here into that file, and saved it: http://www.google.com/codesearch/p?hl=en#LQbkWtxul78/gen/com/android/internal/telephony/ITelephony.java&q=file:(/%7C%5E)com/android/internal/telephony/ITelephony%5C.java$&sa=N&cd=1&ct=rc

    It gave me an error, since it was using the wrong import, so I used the auto-create method that Eclipse suggested, which created a new package within my project, and moved the java file there. All is working now!

    P.S. I have it working with emulators on ALL versions of Android higher than API level 5, which is Android 1.6. In other words, from 2.0 up to 2.3.3 (API levels 6 through 10) it is working!

    ReplyDelete
    Replies
    1. can you please provide the package for 2.3.3. I cannot make it work for 2.3.3. It would be really nice if you help me.

      Delete
  55. Hi Paul,

    pls follow this to include ITelePhony.aidl
    - copy and past ITelePhony.aidl under com.android.internal.telephony package of your Eclipse Project

    - It should generate automatically ITelephony.java under gen folder.

    Regarding PhoneAwayWidget - you need SVN client to download the source-
    http://code.google.com/p/phoneaway/source/checkout

    If you still face same problem, drop me mail.
    Thanks,
    Prasanta

    ReplyDelete
  56. hi prasanta i just use ur code but it completely in emulator but not in real device,do you have some suggestions

    ReplyDelete
  57. Prasanta,
    I've tried the code on HTC Hero with OS 1.5 as well as on HTC Desire HD with OS 2.2 and it worked great but on Samsung Nexus S with OS 2.3 i can see during the installation that the application didn't get the permission:
    "Not granting permission android.permission.MODIFY_PHONE_STATE to package test.phone (protectionLevel=3 flags=0x8446)"
    and on run time i get an exception when i attempt to answer the call.
    Do you think there's a workaround for it (without being root application)?

    ReplyDelete
  58. Hi prasanta,
    i am new to android my name is Rajesh.i saw your blog it is very help full to me but i have a small problem,
    user press dial button in android i need to place a conformation button.how to do this can u help me..

    ReplyDelete
  59. Prasanta,

    I have tried all of your instructions, and still don't understand what you mean by "copy and paste ITelephony into com.android.internal.telephony package of your Eclipse project". How do you create that package in the first place, and is that package within my application project? I've tried copying and pasting the aidl into quite a few places, and it never generates the ITelephony.java file. Thanks for the help in advance!

    ReplyDelete
  60. It looks like you need MODIFY_STATE_PHONE even if you are just ending a call:

    04-10 16:15:20.065: ERROR/DeclineCallsReceiver(1524): ERROR: Neither user 10025 nor current process has android.permission.MODIFY_PHONE_STATE.

    Thanks for the blog!

    ReplyDelete
  61. @Paul - look at Tedd's Droid Tools example that Prasanta reference:

    http://code.google.com/p/teddsdroidtools/source/browse/#svn%2Ftrunk%2Fteddsdroidtools%2Fsrc%253Fstate%253Dclosed

    It shows where the ITelephony.aidl should be in order to get it to be generated in /res for the project. I have that part working.

    ReplyDelete
  62. endCall ending the call on receiver part(on android phone that receives the incoming call), but not at the caller side. Caller hear busy line sound before network timeout expires or redirected to voice mail (in case android has voice mail setup). Any solution to correctly terminate the call ?

    ReplyDelete
  63. Prasanta ,
    Thanx alot !!! this was a really very useful post for me , it helped me in my project and now my project has been selected fr best project of my clg , credit goes 2 u!!!
    Tejas

    ReplyDelete
  64. Hi Prasanta

    Thanks for your all great help. Your opinion and code really help me a lot. I have stuck in one place when i am using switchHoldingAndActive() method in ITelephony.aidl it is implemented well and good, but at run time it is throwing exception "No Such Element Found". Do you have any right idea to help me out.
    Thanks & Regards

    ReplyDelete
  65. Hi Prasanta,

    I have used these two methods
    void switchHoldingAndActive();
    boolean canConference();

    in ITelephony.aidl but geting error like ---

    05-12 22:03:34.486: ERROR/dalvikvm(17603): Could not find method com.android.internal.telephony.ITelephony.switchHoldingAndActive

    Thanking you,
    Regards,
    Saj

    ReplyDelete
  66. Hi Prasanta,

    I tried to work with the setMute function , in the way you described above, but it threw an exception: NoSuchMethodError...
    Notice that I succeed to work with some other function, such as endCall() and it worked fine.

    Any Idea why it knows endCall method but not setMute?

    Thank,
    Tomer

    ReplyDelete
  67. Hello Excellent post, I have an application that have all the names and address in my city, I can find a name with a phone number, with your application I can intercept the number, but will be possible to draw my info in the incoming call of android??
    Thanks Rodney

    ReplyDelete
  68. Hi,

    This works.Thanks.
    Now can you suggest something for outgoing calls?

    ReplyDelete
  69. Hello Prasanta,

    Can you please explain to me why the application reject calls on the emulator and do not work on a real device?

    Thanks in advance. :)

    Regards,

    ReplyDelete
  70. Hello Pransanta,

    I am working with a calling application and i have to first dial a number and after 20 seconds i have to disconnect the call. I understand that API does not allows to control calls. i am trying to make somehtign like this and put a timer but i need your help thanks.

    if(tm.getCallState() == TelephonyManager.CALL_STATE_OFFHOOK){
    // end the call after 20 seconds :-(
    telephonyService.endcall;
    }

    ReplyDelete
  71. Hello Prasanta,

    I have a clarification.

    You have mentioned about the mute on going call.

    Is it possible to mute/Silence mode the incoming call ring before the call is picked.

    Thanks in Advance.
    Sanjeev.O.J

    ReplyDelete
  72. Hi,
    Very useful post.
    facing a problem, when using the setMute and getCallerName methods, shows NoSuchMethodError. Please help me in this
    Thanks in advance

    ReplyDelete
  73. Hi Prasanta,

    how would you suggest to recognize phonecall connect and dial - I need to recognize the event of call start and call connect- the first one is easy OFFHOOK state is called - but what about call connect 10x
    Elad

    ReplyDelete
  74. See https://devmaze.wordpress.com/2011/01/18/using-com-android-internal-part-1-introduction/ for a detailed description of creating your own .jar file for internals thus avoiding use of Java Reflection and the need for attaching the large and heap-error prone framework_intermediates-classes-full-debug.jar
    It also describes how to eliminate the prohibition against using internal's.
    I have it setup now to try.

    ReplyDelete
  75. Hi i am very new in android. Can u please provide me the source code of this (actually i want to block incoming and outgoing call)

    ReplyDelete
  76. @Prasanta Paul

    Out standing !!! Great !!! Salute to you !!!

    ReplyDelete
  77. Works well, one issue I'm having on 2.3 even with the android.permission.MODIFY_PHONE_STATE permission added to my app I still get a SecurityException when I try to turn of the ringer on incoming calls. I am able to hang up on calls though.

    ReplyDelete
  78. Because of security reasons gingerbread has removed the endcall from ITelephony AIDL exposed to app developers. So you cant end the call :(.

    Girish

    ReplyDelete
  79. This is good stuff , but i m not getting how can we pass the array of phone no. for block call !

    ReplyDelete
  80. Hi,It is a good blog guys..But in Android 2.3 we dont have Modify phone state Permission.
    So this code will only work till Android 2.2

    ReplyDelete
  81. Hi Prasanta,
    I tried with the sample code that u have provided...it defintely ends the call but not before the call is received for a very short duration...so can we some how change the priority of the receiver so that it gets the first broadcast and then the other oredered broadcasts are called....

    Waiting for your KT on this...
    Thanks~
    Phil

    ReplyDelete
  82. http://code.google.com/p/android/issues/detail?id=15031

    ReplyDelete
  83. What about newer versions? Does this approach work in 3.0, 3.2 etc OR it's blocked there also - anyone tried this?

    Also in 2.2 this works, then can an app play some audio to the incoming call?

    Any help on this is appreciated.

    Thanks.

    ReplyDelete
  84. Hi Prasanta Paul,

    Thanks for the code. I am trying to get it to work using Netbeans android plugin. I copied/pasted the ITelephony.aidl text above my main class definition. So I can use it as a Nested Interface. And then I copied/pasted this code into my main class:

    [code]
    case TelephonyManager.CALL_STATE_RINGING:
    stateString = "Ringing";
    locked=false;
    try{
    Context context = getBaseContext();
    AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    audioManager.setSpeakerphoneOn(true);
    Class c = Class.forName(telephonyManager.getClass().getName());
    Method m = c.getDeclaredMethod("getITelephony");
    m.setAccessible(true);
    ITelephony telephonyService = (ITelephony) m.invoke(telephonyManager);


    // Silence the ringer and answer the call!
    telephonyService.silenceRinger();
    telephonyService.answerRingingCall();
    }catch(Exception e){System.out.println("Answer Call Error: "+e);}



    break;
    [/code]
    I also added the permissions to the manifest.xml

    I dont get any errors and the program is running on my phone.

    All I'm trying to do right now is answer the call automatically when case is: TelephonyManager.CALL_STATE_RINGING

    Do you not have to provide an implementation of AnserRingingCall()? Because it is only an interface, am I right?

    Do I have to add the whole jar framework aswell?

    Pls help,
    Regards
    Aubrey.

    ReplyDelete
  85. I seem to be getting a "ClassCastException: com.android.internal.telephony.ITelephony$Stub$Proxy"

    I'm lost here,
    Regards
    Aubrey.

    ReplyDelete
  86. Ahh, got it. There was no need to use the framework jar!

    All I had to do was save the ITelephony interface code as ITelephony.java - Then, create folders in the project "root"/src/ folder: (/src/com/android/internal/telephony/)

    Thankyou Pransanta
    Regards
    Aubrey.

    ReplyDelete
  87. Hi Prasantha! I need ur help regarding some application in android .Please reply to this comment so that i can discuss my problem.

    ReplyDelete
  88. Prasanta, hi your post was of great help to me, i was wondering if there is also a way to get the call time, when the person on the other side actually answered the call, using reflection..... thank in advance..

    ReplyDelete
  89. telephonyservice.answerCall(); is not working and
    Neither user 10025 nor current process has android.permission.MODIFY_PHONE_STATE.
    this error show in logcat

    ReplyDelete
  90. Hi Prasanta

    Thanks a million for your post
    I have tried it and worked perfect for me on a small call intent and using your ITelephony endcall method on android 2.3.3

    Rgds,
    Christian

    ReplyDelete
  91. given code is perfectly working on till Android 2.2 but not working with Android 2.3.

    in Android 2.3 Modify_Phone_State permission has been removed soo give any possible solution so that we can do block incoming calls on Android 2.3.

    ReplyDelete
  92. pls..! send reject call project source code link....!

    Thanks

    ReplyDelete
  93. hi prasanta ,
    it was very elegantly handled, can u help me out to write a code by which one can set voicemail for different callers....

    ReplyDelete
  94. Hi,
    For my application i need that whenever during the call in android phone, as the conference starts(when more then two line are joint) the phone go on hold automatically or the headphone and speaker goes mute cant able to hear or talk any thing. i try but can get the solution please give me the solution. my mail address gauravbtl.sitm@gmail.com

    ReplyDelete
  95. Worked. Thanks for this!

    Any hints on how to determine if an outgoing call resulted in a busy signal?

    on a separate note, how well does this work with different OS versions? ie 2.2, 2.3 or 4.0?

    ReplyDelete
  96. Hi,

    endcall() is not working on the target 2.3 onwords version. Can you please help me to implement work around.

    Thanks,
    Naresh

    ReplyDelete
  97. Hi,
    I am not able to access CallManger class from com.android.internal.telephony package. I downloaded framework_intermediates-classes-full-debug.jar file and I added this to my project but am unable to access CallManger class. I think this jar file does't containd CallManger.java class. From where I will get this class?

    ReplyDelete
  98. Hi,

    I want to use com.android.internal.telephony API's for that I downloaded "framework_intermediates-classes-full-debug" jar file and added this to my project in eclipse. But I am unable to import CallManager.java class of that package into my project. I am able to import Call.java class of telephony API but not CallManger.java. Then how to import this class to my project? is there any jar file? plz help me.
    Thanks in advance

    ReplyDelete
  99. hello everybody
    Can I Hide Native Phone App GUI When Incoming Call Comes.can someone show me how to do it ?

    ( my phone is android )

    ReplyDelete
  100. Hi Guys,
    nobody answered the MODIFY_PHONE_STATE issue then I'll do:
    Since Gingerbread (2.3) this permission can be replaced with READ_PHONE_STATE to get anserRingingCall() working....

    ReplyDelete
  101. Hi guys

    Can we use the above to issue a
    disableDataConnectivity()

    ?

    st

    ReplyDelete
  102. thanks , really helpful.

    ReplyDelete
  103. Hi i am able to disconnect the call but the phone rings atleast for 1-2 seconds before the call gets disconnected.Please help.

    ReplyDelete
    Replies
    1. bro...could you mail me the call blocking workspace on lokesh_technocrat@hotmail.com...plz....

      Delete
  104. Hey. It is a really great article. But I cannot seem to download anything. All the links give me a 404 error. Please help

    ReplyDelete
  105. Hi,

    Your tutorial is quite helpful. Would you be willing to write one on sending AT commands (suct as at+csq?) as well?

    Thanks

    ReplyDelete
  106. hi Prasanta
    i am working my project.When have an incoming phone call, the screen has not changed its.How to do it (can you give me a little code for this problem ) ? please help me!

    ReplyDelete
  107. Thanks. Good job! :)

    ReplyDelete
  108. very nice yar after finding a lot i got it.......

    ReplyDelete
  109. Hello Prasanta, Nice tutorial... But my requirement is quite different.. I want to receive incoming call automatically that was I done already now I want to play my own created sound to my caller rather than android will use its default mike.. Can you tell me is it possible or not and how?

    I am waiting for your reply... :)

    Thanks.

    ReplyDelete
  110. Hello Prasanta, Nice tutorial... But my requirement is quite different.. I want to receive incoming call automatically that was I done already now I want to play my own created sound to my caller rather than android will use its default mike.. Can you tell me is it possible or not and how?

    I am waiting for your reply... :)

    Thanks.

    ReplyDelete
    Replies
    1. Hey mansi i am also waiting for the same ... if you got the solution please help me..

      Delete
  111. bro...could you mail me the call blocking workspace on if09033@students.del.ac.id ...plz....

    ReplyDelete
  112. Hi prasanta can you please help me out here., actually i have done every like you only but how to make a active call to hold through programming.. please help me.... is this possible by changing the mode (Audiomanager.setmode(variable)).

    please yar its very urgent for me.. i am searching for this from last one month//...

    ReplyDelete
  113. Hi Prasanta,its usefule article. but i want to know if i want to give automatic call to any number(Ex. 989898989) on particular time then is it possible? scenario is like this i have set message,date,time for particular number from my contact list and now without my/user interaction call should get occurred. is it possible? i did R&D but i confused about the same. you can mail me directly on dhane.onkar@gmail.com thanks in advance.

    ReplyDelete
  114. Great Stuff!! Prasanta.. Thanks a Tonn :)

    ReplyDelete
  115. Hi,

    Can you tell how to put call on Hold?
    is it possible?

    ReplyDelete
  116. You should be able to do that while the incomin call. You see that option on the screen. http://www.intellectsoft.net/windows_phone_development_services.html

    ReplyDelete
  117. Please tell the solution for 2.3+

    ReplyDelete
  118. Hi,
    it seems to be blocked since 2.3

    http://code.google.com/p/android/issues/detail?id=15031#makechanges

    ReplyDelete
  119. well, it seems that this solution using com.android.internal.telephony.ITelephony is great for lower version os builds... I implemented and tested this solution on real devices, where this solution works for android 2.2 os built devices but on higher version of os(upper than v2.3) the part -> Answering incoming call using answerRingingCall() doesn't work at all.

    Can anyone give me any suggestion on this issue?

    ReplyDelete
  120. Hi Prasant
    I am novice in Android development , could u help me writing a code which takes a phone number and duration as argument and then call that number for that a particular duration or if you could point me to some api by using which i can do that would also be fine , till now i am able to give number as argument and then call that number but not able to control time.

    thanks in advance.

    ReplyDelete
  121. Great tutorial , Prasanta.
    I was able to achieve the call control you explained a few days ago.
    Then moving ahead, i wanted to perform call conferencing programmatically using the hidden com.android.internal.telephony.Phone interface.

    But there's no any method to get a reference to this Interface from TelephoneManager like the getITelephony() method.

    Please let me know if you have worked with that hidden Phone interface.

    ReplyDelete
  122. Hi,

    can you please explain me how to detect the incoming call is ended by remote party?

    Thanks & Regards,
    Durgesh Patel
    Java / Android Software Engineer
    Cygnet Infotech Pvt. Ltd.
    Ahmedabad, Gujarat, India.

    ReplyDelete
  123. mute functionality doesn't work as it do is not already available in Itelephony.aidl. Anywaz tuorial is good.

    ReplyDelete
  124. Hi , I'm unable to use this feature. Can you please send me this code

    sumit.sharma@mail.vinove.com

    ReplyDelete
  125. Itelephony.aidl is giving an error, due to which code is not running. Please help to get out of this.can you please send me call block code to this mail.

    sumitsharma1900@gmail.com

    ReplyDelete
  126. Hi,

    I'm trying to use your approach to end the call, but I'm facing some issues. In my phone (LG Optimus) running on android 2.2, I could successfully receive the call but couldn't end it. The endCall() method returns false. Can you please inform whether this works in android 4.0 onwards.

    ReplyDelete
  127. Can anybody tell me how to convert this widget into android app

    sumitsharma1900@gmail.com

    ReplyDelete
  128. Hi
    can it is possible in Android mobile App to detrack Control from mic to other App when call recived and Connection established?????

    ReplyDelete
  129. Did not work in 4.2.1. Any idea how to accomplish these in 4.x? Thanks in advance.

    ReplyDelete
  130. Hey this is not working in ICS. Do you have any idea how to get this work?

    I searched on internet, few are saying that its not possible now. Is it ?

    ReplyDelete
  131. Dear All,
    to provide more Android internal and Hidden method support, I have created one project "InDroid". In this project I'll work on to expose Android's hidden API and important utility methods to empower Application developers with rich Native access.

    Initial version of this Library (1.0) supports hidden APIs of Telephony, Graphics and View system. Please try this Library and let me know your feedback-
    http://code.google.com/p/indroid/

    BR,
    Prasanta

    ReplyDelete
  132. Hi Prasanta

    thanks for posting Idroid Jar but the method answerRingingCall is not working for android 2.3.3

    ReplyDelete
  133. Hi Prasanta,

    Thanks for this tutorial. I have got exception when i run the code "No Method found getITelePhony". Please tell me how to end call in android 4.0

    ReplyDelete
  134. i am getting this error
    java.lang.SecurityException: Neither user 10045 nor current process has android.permission.MODIFY_PHONE_STATE.

    can u please help me ..

    ReplyDelete
  135. Thanks for the tutorial. In this world where almost all people have their own mobile phones, it is good to have a refresher on the latest trends in this type of technology.

    ReplyDelete
  136. Thanks for such nice and useful post.

    I am trying to auto answer and dial number but its not working, can you help me in that ?

    http://stackoverflow.com/questions/21019975/neither-user-10056-nor-current-process-has-android-permission-modify-phone-state

    Thanks
    Juned Khan

    ReplyDelete
  137. Thanks Prasanta,

    I am actually waiting for this type of explanation.

    You are awesome... :)

    ReplyDelete