我使用此代码调用:
Uri callUri = Uri.parse("tel://0000");
Intent callIntent = new Intent(Intent.ACTION_CALL,callUri);
callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_NO_USER_ACTION);
startActivity(callIntent);
我想在以下时间做点什么:
以及如何关闭通话
先谢谢
答案 0 :(得分:0)
您应该使用 TelephonyManager 来处理呼叫。看看下面的课......
private class PhoneCallListener extends PhoneStateListener {
private boolean phoneInACall = false;
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if (TelephonyManager.CALL_STATE_RINGING == state) {
// THE PHONE IS CURRENTLY RINGING!
}
if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
// THE PHONE IS ACTIVE, DIALING OR ON HOLD!
phoneInACall = true;
}
if (TelephonyManager.CALL_STATE_IDLE == state) {
// IDLE - NO ACTIVITY. IF PHONEINACALL WAS TRUE, IT MEANS THE CALL ENDED
if (phoneInACall) {
// RESTART YOUR MAIN ACTIVITY BECAUSE A CALL ENDED!
phoneCalling = false;
}
}
}
}
您可以在 onCreate 方法中使用此类,方法是创建此 PhoneStateListener 的实例并获取 TelephonyManager 的实例来调用监听方法,以收听指定电话状态变化的通知......
PhoneCallListener phoneCallListener = new PhoneCallListener();
TelephonyManager telManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
telManager.listen(phoneCallListener, PhoneStateListener.LISTEN_CALL_STATE);
此代码可以帮助您解决问题:)祝您好运!