android calllog,android – 如何获取callLog.calls中最频繁的值条目的数量?

Call Log Calls entry is this

- Name Number TYPE date called

- Jed 12345 Incoming 7-18-2013

- Roger 14611 Incoming 7-18-2013

- Jed 12345 Incoming 7-18-2013

- Jed 12345 Incoming 7-18-2013

- Kevin 11111 Incoming 7-18-2013

嗨,我想在android中查询,我只会检索

Jed,12345<

我想在sqlite(android查询)中这样做但我不知道要调用哪些函数

这是我使用的代码,但我只能得到最近调用的号码,而不是具有最多条目的号码.我怎么做这个问题?

Date date=new Date() ;

Cursor c = contxt.getContentResolver().query(CallLog.Calls.CONTENT_URI,

null, CallLog.Calls.TYPE + " AND " + CallLog.Calls.INCOMING_TYPE +

" AND " + CallLog.Calls.Date + ">=" + date.getDate() ,

null,

CallLog.Calls.DATE + " DESC LIMIT 1");

if(c!=null)

do{

int callCounter = c.getCount();

String num = callLog_cursor.getString(callLog_cursor

.getColumnIndex(android.provider.CallLog.Calls.NUMBER));

}while(c.moveToFirst());

解决方法:

如果你正在寻找一个单独的查询来完成这项工作,我很遗憾地说它(就我的谷歌技能而言)并不存在.我用另一种你可能觉得有用的方式解决了它.

在您的活动中的某个位置创建此功能:

public static void searchAndDisplay(ArrayList arr) {

ArrayList list1 = new ArrayList();

ArrayList list2 = new ArrayList();

for (int i = 0; i < arr.size(); i++) {

int index = list1.indexOf(arr.get(i));

if (index != -1) {

int newCount = list2.get(index) + 1;

list2.set(index, newCount);

} else {

list1.add(arr.get(i));

list2.add(1);

}

}

for (int i = 0; i < list1.size(); i++) {

System.out.println("Number " + list1.get(i) + " occurs "

+ list2.get(i) + " times.");

}

int maxCount = 0;

int index = -1;

for (int i = 0; i < list2.size(); i++) {

if (maxCount < list2.get(i)) {

maxCount = list2.get(i);

index = i;

}

}

System.out.println("Number " + arr.get(index)

+ " has highest occurrence i.e " + maxCount); // here you might want to do something/return the number with the highest occurences.

}

然后你想要光标你使用这个:

Date date = new Date();

ArrayList allnumbers = new ArrayList();

Cursor c = this.getContentResolver().query(

CallLog.Calls.CONTENT_URI,

null,

CallLog.Calls.TYPE + " AND " + CallLog.Calls.INCOMING_TYPE

+ " AND " + CallLog.Calls.DATE + ">=" + date.getDate(),

null, CallLog.Calls.NUMBER);

allnumbers.clear();

if (c != null)

c.moveToFirst();

for (int i = 0; c.getCount() > i; i++) {

String number1 = c.getString(0);

allnumbers.add(number1);

c.moveToNext();

}

searchAndDisplay(allnumbers);

您可能需要仔细检查您收到的数字是否正确.

让我知道事情的后续.

标签:android,sqlite

来源: https://codeday.me/bug/20191002/1843504.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值