【发布时间】:2013-08-02 18:24:22
【问题描述】:
我有一个监听器来检测来电
每次来电后,我都会向 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 };
【问题讨论】:
-
用户收到的任何来电。无论您是接听电话还是未接电话,它都会在每次来电后向 CallLog 内容提供者查询
标签: android android-contentprovider android-cursor