Get phone call information on android

别来无恙 提交于 2020-05-16 06:33:07

问题


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:

  1. Timestamp and phone number of ingoing/outgoing calls
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!