How to get Call number as well as the duration of the call made by a user in Android?

拜拜、爱过 提交于 2019-12-07 15:03:42

问题


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

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