2
我已經編寫了一個應用程序來訪問外部存儲上的SQLite數據庫。該應用在我的Nexus 4和模擬器上與Android 4.4一起運行良好。由於我將手機升級到了Android 5,因此它不再顯示來自SQLite數據庫的任何數據。 API 21上的仿真器也沒有顯示數據。SQLite SELECT不再適用於Android API 21,但在18
沒有錯誤或異常拋出。該數據庫光標在API 21
打開數據庫這樣乾脆爲空:
String path = myContext.getExternalFilesDir(null).getAbsolutePath() + File.separator + DB_NAME;
myDataBase = SQLiteDatabase.openDatabase(path, null, SQLiteDatabase.OPEN_READWRITE);
查詢是這樣執行的:
Cursor cur = myDataBase.rawQuery("SELECT * FROM employee WHERE employee match ? " +
"ORDER BY firstname, lastname LIMIT 100",
new String[] { "*" + queryString+ "*" });
while (cur.moveToNext()) {
persons.add(getPerson(cur)); // never reaches this since API 21
}
cur.close();
什麼已經從18變到21?
完整的源代碼可以在這裏找到:在Android的5 https://github.com/sebastianhaeni/Contacts
目標sdk在清單? – Suvitruf 2014-11-24 13:44:27
用21和18試過,結果相同 – 2014-11-24 13:45:33
dbHelper的onCreate被調用了嗎? – Simon 2014-11-24 13:47:16