[英]How to manage the states of an outgoing call in Android?
I'm developing an android application for a university exam. 我正在为大学考试开发一个android应用程序。
I use a Samsung Galaxy S3 with original ROM, Android Jelly Bean 4.3. 我使用带原始ROM的Samsung Galaxy S3和Android Jelly Bean 4.3。
I have a problem with detecting the "states" of an outgoing call. 我在检测拨出电话的“状态”时遇到问题。
I need to know when the phone call "start" from my application and "stop" (rejected or not) because i have to pause and restart the playing song of a music service. 我需要知道电话何时从应用程序“开始”和“停止”(是否被拒绝),因为我必须暂停并重新启动音乐服务的播放歌曲。
I have already done it with the incoming calls and it works perfectly in this way: 我已经通过传入呼叫完成了此操作,并且它可以通过以下方式完美运行:
public void onReceive(Context context, Intent intent) {
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
if (Start.getMusicService().isPlaying()) {
pauseService();
isMusicPlaying = true;
}
}
else if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
if (isMusicPlaying){
startService();
isMusicPlaying = false;
}
}
}
For the outgoing calls i register the receiver in the manifest 对于拨出电话,我在清单中注册接收方
<receiver android:name=".Music.OutgoingCallReceiver" >
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
and add the permission 并添加权限
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
I tried this solution for the receiver 我为接收器尝试了此解决方案
public void onReceive(Context context, Intent intent) {
TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(new PhoneStateListener() {
public void onCallStateChanged(int state, String number) {
if (state == TelephonyManager.CALL_STATE_IDLE) {
if (Start.getMusicService().isPlaying()) {
pauseService();
isMusicPlaying = true;
}
}
else if (state == TelephonyManager.CALL_STATE_OFFHOOK) {
if (isMusicPlaying){
startService();
isMusicPlaying = false;
}
}
}
}, PhoneStateListener.LISTEN_CALL_STATE);
}
I have already read other questions buy i didn't find the answer. 我已经读过其他问题,但我没有找到答案。
I hope you can help me. 我希望你能帮助我。
Andrea 安德里亚
make procedure to read logcat of radio, command: 制作程序以读取电台的logcat,命令:
logcat -d -b radio RILJ:D RILC:D *:S
mine on android 2.3, when make outgoing call got output: 我的android 2.3上,当发出拨出电话得到输出时:
06-11 20:38:43.051 D/RILJ ( 429): [4678]< GET_CURRENT_CALLS [id=1,ALERTING,toa=145,norm,mo,0,voc,noevp,,cli=1,,1]
and when answered got output: 当回答得到输出时:
06-11 20:38:50.300 D/RILJ ( 429): [4683]< GET_CURRENT_CALLS [id=1,ACTIVE,toa=145,norm,mo,0,voc,noevp,,cli=1,,1]
so, to detect wether outgoingcall is answered, me make procedure to capture those logs and check if it 因此,要检测是否接听了所有拨出电话,我制定了程序来捕获那些日志并检查是否
contain time > time-when-make-outgoing-call, and
contains string "GET_CURRENT_CALLS" and "ACTIVE".
and... IT WORKS, for me on sonyericsson-android 2.3. 和...对我来说,在sonyericsson-android 2.3上有效。
i don't know if it works on other device and android version, you tell me. 我不知道它是否可以在其他设备和android版本上运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.