Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to retrieve recent call list and favourites list in android?

Tags:

android

I need to call recent call list and favourite call list on the click of respective buttons and need the data in my own list layout.I am new to android and having lot of trouble with this.can anyone please help me..thanks in advance..

like image 943
prof_jack Avatar asked Nov 03 '11 12:11

prof_jack


People also ask

How do I retrieve my old call history on Android?

Retrieving your old call history will depend on the type of Android phone you have and the operating system. Typically, Android phones are limited to storing 500 calls. For Samsung phones to retrieve your call history, go to Settings→ Accounts and backup → Restore Data → Select your phone → Tap Restore.

How do I see my recent calls on Android?

How to see My Recent Calls on Android 1 Open your device's Phone app . 2 Tap Recents . 3 You’ll see one or more of these icons next to each call in your list:Missed calls (incoming) (red)Calls you answered (incoming) (blue)Calls you made (outgoing) (green) See More....

How can I see a list of calls that I’ve made?

You can see a list of calls that you’ve made, answered or missed, and delete calls from the list. Important : Some of these steps only work on Android 6.0 and up. Learn how to check your Android version . Open the Phone app . Tap Recent . To learn more about a call in your history, tap the call Call details.

How to recover deleted call log on Android phone?

How to Recover Deleted Call Log on Android 1 Connect the Android phone to your computer using a USB cord. 2 Allow USB Debugging on your Android phone. 3 Select file type you need a data recovery - Call History. 4 Start to scan and find the deleted call logs on Android phone. 5 Choose the deleted call history to retrieve to Android phone or PC.


2 Answers

With some extra, useful code:

getFavoriteContacts:

Map getFavoriteContacts(){
Map contactMap = new HashMap();

Uri queryUri = ContactsContract.Contacts.CONTENT_URI;

String[] projection = new String[] {
        ContactsContract.Contacts._ID,
        ContactsContract.Contacts.DISPLAY_NAME,
        ContactsContract.Contacts.STARRED};

String selection =ContactsContract.Contacts.STARRED + "='1'";

Cursor cursor = getContentResolver().query(queryUri, projection, selection,null,null);


while (cursor.moveToNext()) {
    String contactID = cursor.getString(cursor
            .getColumnIndex(ContactsContract.Contacts._ID));

    Intent intent = new Intent(Intent.ACTION_VIEW);
    Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(contactID));
    intent.setData(uri);
    String intentUriString = intent.toUri(0);

    String title = (cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)));

    contactMap.put(title,intentUriString);

}
cursor.close();
return contactMap;
}

getRecentContacts:

Map getRecentContacts(){
Map contactMap = new HashMap();

Uri queryUri = android.provider.CallLog.Calls.CONTENT_URI;

String[] projection = new String[] {
        ContactsContract.Contacts._ID,
        CallLog.Calls._ID,
        CallLog.Calls.NUMBER,
        CallLog.Calls.CACHED_NAME,
        CallLog.Calls.DATE};

String sortOrder = String.format("%s limit 500 ", CallLog.Calls.DATE + " DESC");


Cursor cursor = getContentResolver().query(queryUri, projection, null,null,sortOrder);


while (cursor.moveToNext()) {
    String phoneNumber = cursor.getString(cursor
            .getColumnIndex(CallLog.Calls.NUMBER));

    String title = (cursor.getString(cursor.getColumnIndex(CallLog.Calls.CACHED_NAME)));

    if(phoneNumber==null||title==null)continue;

    String uri = "tel:" + phoneNumber ;
    Intent intent = new Intent(Intent.ACTION_CALL);
    intent.setData(Uri.parse(uri));
    String intentUriString = intent.toUri(0);

    contactMap.put(title,intentUriString);

}
cursor.close();
return contactMap;
}
like image 185
Oded Breiner Avatar answered Nov 15 '22 13:11

Oded Breiner


For getting recent calls list,you can use CallLog in android. Here is a good tutorial.This is also helpful.

You can use it for all outgoing calls like this :

Cursor cursor = getContentResolver().query(android.provider.CallLog.Calls.CONTENT_URI,null, android.provider.CallLog.Calls.TYPE+"="+android.provider.CallLog.Calls.OUTGOING_TYPE, null,null);

For all types of calls,use it like:

Cursor cursor = getContentResolver().query(android.provider.CallLog.Calls.CONTENT_URI,null, null, null,null);
like image 44
Hiral Vadodaria Avatar answered Nov 15 '22 13:11

Hiral Vadodaria