user1426956
user1426956

Reputation: 123

Android get Missed call

So I want to get the count of the missed calls like the telephonyapplication displays in the notification bar

so I came up with this code :

String[] projection = { CallLog.Calls.CACHED_NAME, CallLog.Calls.CACHED_NUMBER_LABEL, CallLog.Calls.TYPE };
String where = CallLog.Calls.TYPE+"="+CallLog.Calls.MISSED_TYPE;          
Cursor c = this.getContentResolver().query(CallLog.Calls.CONTENT_URI,projection,where, null, null);
c.moveToFirst();    
Log.d("CALL", ""+c.getCount()); //do some other operation

if(c.getCount() > 0)//...etc etc
    Toast.makeText(app.this,String.valueOf(c.getCount()), Toast.LENGTH_LONG).show(); 

This code gives me the toatl amount of missed calls but I want only the newest calls which are displayed in the notification bar

has anybody an idea how to do that ?

Upvotes: 3

Views: 5907

Answers (3)

Vaibhav
Vaibhav

Reputation: 72

How is the code posted by gc hong displaying the latest missed calls?Its working very correct but how is it doing it.

String PATH = "content://call_log/calls";

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

String sortOrder = CallLog.Calls.DATE + " DESC";

StringBuffer sb = new StringBuffer();
 sb.append(CallLog.Calls.TYPE).append("=?").append(" and 
").append(CallLog.Calls.IS_READ).append("=?");

Cursor cursor = context.getContentResolver().query(
            Uri.parse(PATH),
            projection,
            sb.toString(),
            new String[] { String.valueOf(Calls.MISSED_TYPE), "0" 
},sortOrder);

Upvotes: 0

gc Hong
gc Hong

Reputation: 21

String PATH = "content://call_log/calls";

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

String sortOrder = CallLog.Calls.DATE + " DESC";

StringBuffer sb = new StringBuffer();
sb.append(CallLog.Calls.TYPE).append("=?").append(" and ").append(CallLog.Calls.IS_READ).append("=?");

Cursor cursor = context.getContentResolver().query(
                Uri.parse(PATH),
                projection,
                sb.toString(),
                new String[] { String.valueOf(Calls.MISSED_TYPE), "0" },sortOrder);

https://play.google.com/store/apps/details?id=com.meaning36.msreminder

Upvotes: 2

Ran
Ran

Reputation: 4147

CallLog.Calls also has IS_READ and NEW fields.

I believe that you should add to your where string - IS_READ = 0 .

Note that IS_READ is from API Level 14 and NEW is from API Level 1, so I would check them both.

http://developer.android.com/reference/android/provider/CallLog.Calls.html#IS_READ

Upvotes: 2

Related Questions