2

We have developed an application for the Android platform with a SQLite database preloaded. Using SQLiteOpenHelper, in the first execution of the application, we copy the database from “Assets” for the application data directory (/ data / data / br.com.lwu / databases / appdatabase.sqlite). This works, in the most of devices. But we're having problems with LG mobile phones below:

  • LG Optimus One
  • LG-P500
  • LG-P500h

Apparently, the database is copied correctly. But the application can not access the database (such table). We need help!

// 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;

            }

    }    
theomega
  • 31,591
  • 21
  • 89
  • 127

1 Answers1

0

Try changing:

myDataBase = SQLiteDatabase.openDatabase(myPath, null,
            SQLiteDatabase.OPEN_READWRITE);

To this:

myDataBase = SQLiteDatabase.openDatabase(myPath, null,
          SQLiteDatabase.OPEN_READWRITE | SQLiteDatabase.NO_LOCALIZED_COLLATORS);

Doing so will not require you to have mandatory table android_metadata required by android vm in case if its missing in your database.

waqaslam
  • 67,549
  • 16
  • 165
  • 178