Skip to content

Instantly share code, notes, and snippets.

@s90304a123
Created August 28, 2015 03:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s90304a123/f4db821eec5afe41247c to your computer and use it in GitHub Desktop.
Save s90304a123/f4db821eec5afe41247c to your computer and use it in GitHub Desktop.
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