Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
android直接關閉來電 必須要用sdk api level 8才可以正常使用
/**
*
* 直接關閉來電
*
* @throws NoSuchMethodException
* @throws InvocationTargetException
* @throws IllegalAccessException
* @throws ClassNotFoundException
*/
private void endCallIfBlocked( ) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, ClassNotFoundException
{
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
Class<?> c = Class.forName(tm.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
Object telephonyService = m.invoke(tm);
Class<?> telephonyServiceClass = Class.forName(telephonyService.getClass().getName());
Method endCallMethod = telephonyServiceClass.getDeclaredMethod("endCall");
endCallMethod.invoke(telephonyService);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.