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

断了今生、忘了曾经 提交于 2019-12-05 20:47:14
bindal

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"))
                {
}

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