3

所以我想获得未接来电的计数,例如通知栏中显示的电话应用程序

所以我想出了这段代码:

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(); 

这段代码给了我未接来电的总数,但我只想要通知栏中显示的最新来电

有人知道怎么做吗?

4

3 回答 3

2

CallLog.Calls 也有 IS_READ 和 NEW 字段。

我相信你应该添加到你的 where 字符串 - IS_READ = 0 。

请注意,IS_READ 来自 API 级别 14,NEW 来自 API 级别 1,所以我会检查它们。

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

于 2012-06-14T15:16:11.870 回答
2
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

于 2015-02-08T13:03:59.150 回答
0

gc hong 发布的代码如何显示最新的未接电话?它的工作非常正确,但它是如何做到的。

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);
于 2017-06-15T21:40:27.007 回答