问题
I need to get the call number as soon as he makes the call from his android mobile and then when the call ends then i need the duration of the call.
回答1:
Create One broadcast receiver and write following in your receiver onReceive()
method
this receiver return last record of your call but make some time delay so it can return current record.
Cursor c=context.getContentResolver().query(android.provider.CallLog.Calls.CONTENT_URI,null, null, null,android.provider.CallLog.Calls.DATE + " DESC");
int numberColumn = c.getColumnIndex(android.provider.CallLog.Calls.NUMBER);
int dateColumn = c.getColumnIndex(
android.provider.CallLog.Calls.DATE);
// type can be: Incoming, Outgoing or Missed
int typeColumn = c.getColumnIndex(android.provider.CallLog.Calls.TYPE);
int DurationColumn = c.getColumnIndex(android.provider.CallLog.Calls.DURATION);
Write following Your mainfest file
<receiver android:name="Your Receiver">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
In onRecieve put this
Bundle bundle = intent.getExtras();
Set<String> keys = bundle.keySet();
for (String key : keys) {
Log.i("MYAPP##", key + "="+ bundle.getString(key));
if(bundle.getString(key).equals("IDLE"))
{
}
}
来源:https://stackoverflow.com/questions/9030162/how-to-get-call-number-as-well-as-the-duration-of-the-call-made-by-a-user-in-and