gpt4 book ai didi

android - 如何知道电话已结束?

转载 作者:行者123 更新时间:2023-11-29 01:47:57 26 4
gpt4 key购买 nike

通话结束时手机的当前状态是什么。

在android中有三种状态。

TelephonyManager.CALL_STATE_IDLE
TelephonyManager.CALL_STATE_OFFHOOK
TelephonyManager.CALL_STATE_RINGING:

最佳答案

这段代码对我有用。希望对你有帮助

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.Log;

public class CallStateReceiver extends BroadcastReceiver {

private final String LOG_TAG = "CallStateReceiver";

public static String prevState = TelephonyManager.EXTRA_STATE_IDLE;

@Override
public void onReceive(Context context, Intent intent) {

Bundle bundle = intent.getExtras();
if (bundle == null) {
return;
}

String state = bundle.getString(TelephonyManager.EXTRA_STATE);

if (state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_IDLE)
&& !prevState.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_IDLE)) {

Log.i(this.LOG_TAG, "Call ended"));
}

prevState = state;
}
}

关于android - 如何知道电话已结束?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20257222/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com