着信コールを検出するためにリスナーの下に
ある 着信コールのたびに CallLog コンテンツ プロバイダにクエリを作成する
ほんの数秒前にすでにコールがログに記録されていても、カーソルは常に null を返す
ところで、プロジェクトを実行する前にコール ログをクリアしました日食
では、着信コールのたびにカーソルを最初の行に向けることができるようにしたいのですが、うまくいきません
// 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 };