0

i m using the below code to end call, but its not happening.

     private void endCallIfBlocked(String callingNumber) { 
             try { 
               TelephonyManager tm = (TelephonyManager) getApplicationContext().getSystemService(getApplicationContext().TELEPHONY_SERVICE); 
               Class c = Class.forName(tm.getClass().getName()); 
               Method m = c.getDeclaredMethod("getITelephony"); 
               m.setAccessible(true); 
               ITelephony telephonyService = (ITelephony) m.invoke(tm);
               telephonyService = (ITelephony) m.invoke(tm); 

               telephonyService.silenceRinger(); 
               telephonyService.endCall(); 
             } 
             catch (Exception e) { 
               e.printStackTrace(); 
             } 
           }

    }

i'm failing to get 'getITelephony' object, it will throw exception. I'm using samsung galaxy s duos phone. How to block calls in this programatically

1 Answers1

0

The getITelephony Reflection method is deprecated as of Android 4+.

So you can't use it on Android 4+.

ChuongPham
  • 4,761
  • 8
  • 43
  • 53
  • Why reflection method is deprecated for android 4+? Please reference. – xoxol_89 Sep 30 '14 at 13:49
  • The `getITelephony` Reflection method is deprecated - not Reflection itself. Please read my answer again. – ChuongPham Sep 30 '14 at 13:55
  • Thanks ChuongPham you r right. Can u provide me any alternative way to implement without getittelephony. Is it possible or not – FeelzDroid Sep 30 '14 at 19:17
  • If you search for **getITelephony** in SO search function, you should find a few posts discussing alternatives to using **getITelephony**. (Here's the [URL](http://stackoverflow.com/search?q=getITelephony) for your convenience if you don't want to search yourself.) You may have to try the answers found in these posts and see which ones work / don't work, and implement them as you please. Also, if I have answered your question, then please tick it so your post moved off the Unanswered queue. Thanks. ;) – ChuongPham Oct 01 '14 at 10:56