开发者

android database from the assets folder

Is there a way to directly access the sqlite database from the assets folder, or is it always necessary to first 开发者_JS百科copy this db to the device data directory, in the app's database folder?

(Example - Environment.getDataDirectory()+"/data/com.example.myapp/databases/myDb.db")

I ask because I have a db that is quite large (about 11MB) and has to be shipped with the app. After the database has been copied to the data directory, the app will take twice the space. I want to avoid this.

Also, is it possible to delete the contents of the asset folder after the app has been installed? This would help save some space.

Thanks


assets folder is a compile time folder. You cannot access without copying in your linux


yes you can delete the files from the database from the assets folder : you can use "android.resource://"+getPackageName() + "/" to access the folder and then use

File f=new File(_pathToAssestFolder,databasename);
        if(f.exists())
        {f.delete();
        }

but do it in the last line of onCreate() function;

try it

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜