我正在编写一个应该检测来电/去电并记录它们的应用程序。我已经设法让广播接收器注册并开始录制通话,但我无法让它停止。
附件是我编写的相关 BroadcastReciever 的代码,顺便说一句,它是从服务中调用的。
public class IncomingCall extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
if(TelephonyManager.EXTRA_STATE_OFFHOOK.equals(state)){
String incnum = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
int day = new Date().getDate(), mont = new Date().getMonth() , yea = new Date().getYear(), hou = new Date().getHours(), min = new Date().getMinutes();
String s = ""+day+"_"+mont+"_"+yea+"_"+hou+"_"+min+"_"+incnum+"_Incoming"+".3gp";
final AudioRecorder ar = new AudioRecorder(s, context);
ar.start();
Thread th = new Thread(){
public void run(){
String stat = TelephonyManager.ACTION_PHONE_STATE_CHANGED;
while(stat == TelephonyManager.EXTRA_STATE_OFFHOOK){
stat = TelephonyManager.ACTION_PHONE_STATE_CHANGED;
}
ar.stop();
}
};
th.start();
}
}
请告知,我在网上找不到有关类似问题的任何详细信息:\