有没有办法在拒绝来电后立即运行一个应用程序?
我试图寻找解决方案,但我找不到任何解决方案。
提前致谢...
答案 0 :(得分:0)
使用PhoneStateListener查看呼叫何时结束。您很可能需要触发侦听器操作以等待调用启动(等待直到从PHONE_STATE_OFFHOOK再次更改为PHONE_STATE_IDLE),然后编写一些代码以使您的应用程序重新启动IDLE状态。
您可能需要在服务中运行侦听器以确保其保持运行状态并重新启动应用程序。一些示例代码:
EndCallListener callListener = new EndCallListener();
TelephonyManager mTM = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
mTM.listen(callListener, PhoneStateListener.LISTEN_CALL_STATE);
听众定义:
private class EndCallListener extends PhoneStateListener {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if(TelephonyManager.CALL_STATE_RINGING == state) {
Log.i(LOG_TAG, "RINGING, number: " + incomingNumber);
}
if(TelephonyManager.CALL_STATE_OFFHOOK == state) {
//wait for phone to go offhook (probably set a boolean flag) so you know your app initiated the call.
Log.i(LOG_TAG, "OFFHOOK");
}
if(TelephonyManager.CALL_STATE_IDLE == state) {
//when this state occurs, and your flag is set, restart your app
Log.i(LOG_TAG, "IDLE");
}
}
}