本文介绍了跟踪一个电话通话时长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能通过自己的电池供应商利用用户手机,并跟踪一个电话的长度?
Is it possible to utilize the users phone through their cell provider, and track the length of a phone call?
因此,用户presses在应用程序中的一个按钮现在所说的。呼叫开始到pre确定的数字。我们记录的开始时间。通话结束后,我们计算出有多少分钟内使用。
So the user presses a button in the app "Call Now". A call begins to a pre-determined number. We record the start time. When the call ends, we calculate how many minutes were used.
可能?
推荐答案
要计算呼入,呼出电话时谈到使用下面的广播接收器:
To calculate time talked for both incoming , outgoing calls use the following broadcast receiver :
public class CallDurationReceiver extends BroadcastReceiver {
static boolean flag = false;
static long start_time, end_time;
@Override
public void onReceive(Context arg0, Intent intent) {
String action = intent.getAction();
if (action.equalsIgnoreCase("android.intent.action.PHONE_STATE")) {
if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(
TelephonyManager.EXTRA_STATE_RINGING)) {
start_time = System.currentTimeMillis();
}
if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(
TelephonyManager.EXTRA_STATE_IDLE)) {
end_time = System.currentTimeMillis();
//Total time talked =
long total_time = end_time - start_time;
//Store total_time somewhere or pass it to an Activity using intent
}
}
}
填写您的接收器在这样的清单文件:
Register your receiver in your manifest file like this:
<receiver android:name=".CallDurationReceiver">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
另外补充的使用权限:
Also add the uses permission:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
这篇关于跟踪一个电话通话时长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!