2
우리는 SQLite 데이터베이스가 미리로드 된 Android 플랫폼 용 애플리케이션을 개발했습니다. SQLiteOpenHelper를 사용하여 응용 프로그램을 처음 실행할 때 응용 프로그램 데이터 디렉토리 (/ data/data/br.com.lwu/databases/appdatabase.sqlite)의 "Assets"에서 데이터베이스를 복사합니다. 대부분의 장치에서 작동합니다.LG 휴대폰이 SqLite 데이터베이스에 액세스 할 수 없습니다.
- LG 옵티머스 LG-P500
- LG-P500h는
분명히, 데이터베이스를 복사 한
// Copy Database:
private static String DB_PATH = "/data/data/br.com.lwu/databases/";
private static String DB_NAME = "appdatabase.sqlite";
private void copyDataBase() throws IOException{
InputStream myInput = myContext.getAssets().open(DB_NAME);
String outFileName = DB_PATH + DB_NAME;
OutputStream myOutput = new FileOutputStream(outFileName);
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
myOutput.flush();
myOutput.close();
myInput.close();
}
public void openDataBase() throws SQLException{
String myPath = DB_PATH + DB_NAME;
if (myDataBase == null) {
myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);
}
}
@Override
public synchronized void close() {
super.close();
if (myDataBase != null)
if (myDataBase.isOpen()) {
myDataBase.close();
myDataBase = null;
}
}
코드를 표시하십시오. 복사 한 후 데이터베이스에 어떻게 액세스하고 있습니까? – waqaslam
이것은 코드입니다 ... –
문제와 관련하여 개인 저장 경로를 가정하지 말고 적절한 API에서 가져와야합니다. –