我已在manifest.xml
文件中授予权限
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
并定义一个接收器:
<receiver android:name=".OutgoingCallReceiver">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
接收文件是:
public class OutgoingCallReceiver extends BroadcastReceiver {
public static String TAG = "AUTODIAL";
static long start_time, end_time, call_duration;
String number;
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "intent get data : "+intent.getData(), Toast.LENGTH_LONG).show();
String action = intent.getAction();
String state=intent.getStringExtra(TelephonyManager.EXTRA_STATE);
Toast.makeText(context, "Phone State : "+state, Toast.LENGTH_LONG).show();
if(state==null) {
number=intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Toast.makeText(context, "Out going Phone number : "+number, Toast.LENGTH_LONG).show();
}
if (action.equalsIgnoreCase("android.intent.action.PHONE_STATE")) {
if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
start_time = System.currentTimeMillis();
}
if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
end_time = System.currentTimeMillis();
}
call_duration = end_time - start_time;
}
}
在这里,它提供了全部通话时间,而不仅仅是我从我的应用程序拨打的通话时间。
拨号后是否可以返回我的应用程序?