2

I want opy some static info from database from assets (dont need copy on device).

How I can do it?

This code open database from inner folder:

public SQLiteHelper(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
    this.context = context;
}
MyNameIs
  • 832
  • 1
  • 8
  • 19
Artem
  • 4,569
  • 12
  • 44
  • 86
  • 1
    instead of the `DATABASE_NAME`, `(path to assets) + "\" + DATABASE_NAME` – SorryForMyEnglish Jun 18 '15 at 11:30
  • и будет работать? Попробую. Как вы там? – Artem Jun 18 '15 at 11:33
  • 1
    "(dont need copy on device)" -- that is not possible. SQLite needs a local file on the filesystem. Either use `SQLiteAssetHelper` as suggested in the answer, or do not store a SQLite database in assets, but instead something else that you can parse yourself. – CommonsWare Jun 18 '15 at 11:37
  • 1
    обязано работать) только там прийдеться путь к асетам скорее всего хардкодить, из системы у меня не получалось получить коректный путь. я в россию свалил) – SorryForMyEnglish Jun 18 '15 at 11:38

1 Answers1

3

Try to use SQLiteAssetHelper, which has all the code that you need to install a pre-packaged database when your app is first run.

Ref : Reading sqlite file from asset folder

Community
  • 1
  • 1
Haresh Chhelana
  • 24,720
  • 5
  • 57
  • 67