如何确定分钟,用户在GSM电话是多少? [英] How to determine the number of minutes the user is being in a GSM call?
本文介绍了如何确定分钟,用户在GSM电话是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图确定多久用户一直处于GSM通话。这是可能使用TelephonyManager?谢谢。
I'm trying to determine for how long a user has been in a GSM call. Is that possible using the TelephonyManager?Thank you.
推荐答案
您可以设置TelephonyManager的监听器。
试试这个。
You can set a listener on TelephonyManager. Try this.
long startCallTime = 0;
private void setTelephonyManagerCallListener(){
TelephonyManager tm = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
tm.listen(phoneCallStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}
private PhoneStateListener phoneCallStateListener = new PhoneStateListener(){
public void onCallStateChanged(int state, String incomingNumber) {
switch (state){
case TelephonyManager.CALL_STATE_OFFHOOK:
startCallTime = System.currentTimeMillis();
break;
case TelephonyManager.CALL_STATE_RINGING:
case TelephonyManager.CALL_STATE_IDLE:
if (startCallTime>0){
long endCallTime = System.currentTimeMillis();
long durationInMillis = endCallTime - startCallTime;
startCallTime = 0;
}
break;
}
};
};
这篇关于如何确定分钟,用户在GSM电话是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文