how to disconnect the call in android 4.1.2 nexus programmatically

删除回忆录丶 提交于 2019-12-09 13:09:30

问题


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().


回答1:


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



来源:https://stackoverflow.com/questions/13230512/how-to-disconnect-the-call-in-android-4-1-2-nexus-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!