我在表格中有一些值,我试图根据phoneNumber进行检索。查询在小于4.3的设备中执行正常但在4.3以后的设备中 cursor.getCount()始终返回0.
我是否需要添加任何权限或修复。以下是我用来从sqlite获取值的代码。
public ArrayList<Message> getMsgTxtBasedOnNumber(String name, String number) {
String selectQuery = "SELECT * FROM " + TABLE_MSG_LOGS + " WHERE " + MSG_SENDER_NUMBER + " = " + number;
Cursor cur = null;
try {
SQLiteDatabase db = this.getReadableDatabase();
cur = db.rawQuery(selectQuery, null);
System.out.println("" + cur.getCount());
// looping through all the rows
if (cur.moveToFirst()) {
do {
Message msg = new Message();
msg.setSenderName(cur.getString(1));
msg.setSenderNumber(cur.getString(2));
msg.setTextDateTime(cur.getString(3));
msg.setTxtMsg(cur.getString(4));
msgBasedOnName.add(msg);
} while (cur.moveToNext());
}
cur.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return msgBasedOnName;
}
}