问题
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