问题
I've been trying to figure out how to develop a requirement of one of my projects. The requirement is to get information about phone calls:
- Timestamp and phone number of ingoing/outgoing calls
- Timestamp and reason of finished call (call ended by user, network unreachable...)
What I found until now is not so much. This next link
http://developer.android.com/reference/android/telephony/PhoneStateListener.html
Talks about creating a listener to get incoming calls phone number.
Anyone can help me with the rest of functionality? where to get the outgoing information of phone calls? Is there any way to know when a phone call is finished, and the reason?
Thank you in advance,
回答1:
private void getCallLogDetail( Context context ) {
String[] projection = new String[] {
BaseColumns._ID,
CallLog.Calls.NUMBER,
CallLog.Calls.TYPE,
CallLog.Calls.DURATION
};
ContentResolver resolver = context.getContentResolver();
Cursor cur = resolver.query(
CallLog.Calls.CONTENT_URI,
projection,
null,
null,
CallLog.Calls.DEFAULT_SORT_ORDER );
if( !cur.isAfterLast()) {
int numberColumn = cur.getColumnIndex( CallLog.Calls.NUMBER );
int typeColumn = cur.getColumnIndex( CallLog.Calls.TYPE );
int durationcolumn = cur.getColumnIndex(CallLog.Calls.DURATION);
String number = cur.getString( numberColumn );
String type = cur.getString( typeColumn );
String duration = cur.getString(durationcolumn);
cur.moveToNext();
}
}
来源:https://stackoverflow.com/questions/24927617/get-phone-call-information-on-android