在Android1.5版本之前,实现挂断电话是非常容易的事,只需要调用TelephonyManager的endCall()方法就可以了,但在1.5版本之后,Google工程师为了手机的安全期间,把endCall的方法隐藏掉了。所以实现挂断电话可以通过反射的方法,执行endCall方法。具体实现如下:
TelephonyManager在源码里是这样描述的:Context.getSystemService(Context.TELEPHONY_SERVICE)},我们通过TELEPHONY_SERVICE系统服务调用就可以获取。
registerService(TELEPHONY_SERVICE, new ServiceFetcher() {
public Object createService(ContextImpl ctx) {
return new TelephonyManager(ctx.getOuterContext());
}});
而 android.os.ServiceManager 有getService方法
/**
* Returns a reference to a service with the given name.
*
* @param name the name of the service to get
* @return a reference to the service, or <code>null</code> if the service doesn't exist
*/
public static IBinder getService