Created
August 28, 2015 03:16
-
-
Save s90304a123/f4db821eec5afe41247c to your computer and use it in GitHub Desktop.
android直接關閉來電 必須要用sdk api level 8才可以正常使用
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* 直接關閉來電 | |
* | |
* @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