Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to disconnect the call in android 4.1.2 nexus programmatically

i am able to disconnect the call programmatically for incoming unknown number call in android 2.2. But in android 4.1, its not working.

Working Code to disconnect the call in android 2.2:

private Class c;    
private  Method m;    
private com.android.internal.telephony.ITelephony telephonyService;    
public void onReceive(Context context, Intent intent)     
{    
   Bundle b = intent.getExtras();    
   String state = b.getString(TelephonyManager.EXTRA_STATE);    
   if(state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING))   
   {    
     TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);    
     c = Class.forName(tm.getClass().getName());    
     m = c.getDeclaredMethod("getITelephony");    
     m.setAccessible(true);    
     telephonyService = (ITelephony) m.invoke(tm);    
     telephonyService.silenceRinger();   
     telephonyService.endCall();    
   }    
}

Please help me.Thanks in advance

Finally I got a solution for 2.6 version .

MODIFY_PHONE_STATE permission is no longer working on silenceRinger() since 2.3+, but endCall is just fine. So the solution is to comment out the call to silenceRinger().

like image 257
AndroidRaji Avatar asked Nov 05 '12 10:11

AndroidRaji


1 Answers

MODIFY_PHONE_STATE is no longer working on silenceRinger() since 2.3+, but endCall is just fine.

So the solution is to comment out the call to silenceRinger().

And a simple example:

 http://androidbridge.blogspot.ro/2011/05/how-to-answer-incoming-call-in-android.html

Cheers

like image 172
MSA Avatar answered Oct 14 '22 06:10

MSA