0

When I am running android application it stores its database directly on the internal memory of the emulator. The application (.apk file) is stored on external storage. The size of the database is 230MB. I have the following lines in my manifest.xml:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<manifest android:installLocation="preferExternal" >

and the following code that results in the error, INSTALL_FAILED_DEXOPT :

public void copyDatabase() throws IOException 
    {
        if(!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))
        {
            Toast.makeText(mycontext,"External Sd card not mounted", Toast.LENGTH_LONG).show();
        }
        try
        {
            InputStream in=mycontext.getAssets().open("Demo.db");
            File outFile =new File(Environment.getExternalStorageDirectory()+File.separator+ "Demo.db);
            outFile.createNewFile();
            OutputStream out= new FileOutputStream(outFile);
            byte[] buf = new byte[1024];
            int len;
            while((len = in.read(buf))> 0)
            {
                out.write(buf,0,len);
            }
            out.close();
            in.close();
            Log.i("copyDatabase","Database Has been transferred");

        }
        catch(IOException e)
        {
            Log.i("CopyDatabase","could not copy database");
        }

    }
    public  boolean checkDatabase() 
    {   
        SQLiteDatabase checkdb=null;
    try
    {
        String myPath="/sdcard/demo.db";
        checkdb=SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);

        Log.i("checkDatabase database path",checkdb.getPath());
    }
    catch(SQLiteException e)
    {
        Log.e("Database doesn`t exist",e.toString());
    }
    if(checkdb!=null)
    {
        checkdb.close();
    }
    return checkdb != null ? true : false;


    }
    public void openDatabase() throws SQLException
    {
        String myPath="/sdcard/demo.db"
        myDatabase=SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);
    }
Johannes Pille
  • 4,073
  • 4
  • 26
  • 27
Pranita Patil
  • 791
  • 1
  • 9
  • 16
  • Have you ever tried with these answers [1. Copy .db to sdcard](http://stackoverflow.com/a/2661882/940096) and [2.Import/Export db](http://stackoverflow.com/a/6542214/940096) – Praveenkumar Apr 20 '12 at 12:21
  • A third way, to do the upgrade, albeit not the preferred, is to open a handle to each database, and run a select * on the old table / multiple inserts for the new table (for each table). This gives you the ability, for database upgrades, to customize what tables are changed and could be coupled with the SQLiteOpenerHelper. – Blaskovicz Apr 20 '12 at 12:26
  • Strongly related: [How to backup database file to sdcard on android?](http://stackoverflow.com/questions/1995320/how-to-backup-database-file-to-sdcard-on-android) – Tim Post Apr 21 '12 at 17:37
  • Extremely sorry..Actually I dn`t want copying existing database into sd card..I want actually which we create database from existing database it should directly store on sd card . actually it is saved or created in internal memory on tablet...database is too big 230MB. Due to this my application hang while running and tablet become slow. sorry for late reply. – Pranita Patil Jun 21 '12 at 09:56
  • i able to copy and store database directly into sdcard .opening database in activity also.But giving error no such table "table_name" exist.when i see through adb shell it is shown.I am not getting what is error – Pranita Patil Jun 22 '12 at 06:24

0 Answers0