Get Last Call Duration in android

后端 未结 9 1575
北荒
北荒 2020-12-03 15:20

I am looking for an easiest way to get call duration of last dialed number. So for e.g if I have made a call to my mom once I cut the call a notification with the duration s

9条回答
  •  死守一世寂寞
    2020-12-03 16:04

    This code works fine for me.......

    void retriveCallSummary() {
    
                Log.i("*****retriveCallSummary******","Call retrive method worked");
                StringBuffer sb = new StringBuffer();
                Uri contacts = CallLog.Calls.CONTENT_URI;
                Cursor managedCursor = mContext.getContentResolver().query(
                        contacts, null, null, null, null);
                int number = managedCursor.getColumnIndex( CallLog.Calls.NUMBER ); 
                int duration1 = managedCursor.getColumnIndex( CallLog.Calls.DURATION);
                if( managedCursor.moveToFirst() == true ) {
                    String phNumber = managedCursor.getString( number );
                    String callDuration = managedCursor.getString( duration1 );
                    String dir = null;
                    sb.append( "\nPhone Number:--- "+phNumber +" \nCall duration in sec :--- "+callDuration );
                    sb.append("\n----------------------------------");
                        Log.i("*****Call Summary******","Call Duration is:-------"+sb);
                }
                managedCursor.close();
            }
    

提交回复
热议问题