gpt4 book ai didi

android - 为什么我的游标返回 null?

转载 作者:太空狗 更新时间:2023-10-29 12:46:07 25 4
gpt4 key购买 nike

我下面有一个监听器来检测来电
每次来电后,我都会向 CallLog 内容提供程序查询
我的光标总是返回 null,即使几秒钟前已经记录了一个调用
顺便说一句,在 eclipse 中运行项目之前我清除了我的通话记录
我希望能够在每次来电后将我的光标指向第一行,但它不起作用

// Listener to detect incoming calls.

private class CallStateListener extends PhoneStateListener {

@Override
public void onCallStateChanged(int state, String incomingNumber) {

if (previousState == TelephonyManager.CALL_STATE_RINGING
&& state == TelephonyManager.CALL_STATE_IDLE) {

cursor = context.getContentResolver().query(
CallLog.Calls.CONTENT_URI, projection, null, null,
Calls.DEFAULT_SORT_ORDER);

Log.i("SIZE OF CURSOR", String.valueOf(cursor.getCount()));

if (cursor.moveToFirst()) {

}// end if
}// end if

Log.i("onCallStateChanged",
String.format("State changed to %d", state));

previousState = state;

}// end onCallStateChanged()
}// end CallStateListener class

Cursor cursor;
private String[] projection = new String[] { Calls.TYPE, Calls.NUMBER };

最佳答案

我同样从通话后日志中读取了通话,遇到了一些问题,但有一个可行的解决方案。有两件事需要考虑:

1) 我在某些设备上使用常量时遇到了问题

CallLog.Calls.CONTENT_URI

尝试直接使用 URI 字符串:

Uri.parse("content://call_log/calls")

2) 您在通话结束后读取通话记录的速度太快,让您的 Listener 休眠 1000 毫秒,让通话记录在查询之前更新。

关于android - 为什么我的游标返回 null?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18013948/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com