Stephan
Stephan

Reputation: 4443

Extract file from .apk?

in my android app I'm using an own java library that extracts a .db-file from jar. In Java desktop it works well, but when I try to do it on android, the inputstream blocks forever. The copy method looks like this:

InputStream in = classloader.getResourceAsStream(...);
OutputStream out = new FileOutputStream(new File(...));
try {
  while ((read = in.read()) != -1) {
    out.write(read);
  }
} finally {
  try {
    in.close();
  } catch (final Exception e) {
    LOGGER.debug("Error", e);
  }

  try {
    out.close();
  } catch (final Exception e) {
    LOGGER.debug("Error", e);
  }
}

I want to copy this file to the external files dir and android.permission.WRITE_EXTERNAL_STORAGE is granted.

Is there a way to access the file in /data/app/...apk? If not, how can I detect that it can not be accessed without blocking forever?

Upvotes: 1

Views: 1196

Answers (3)

Lukas Knuth
Lukas Knuth

Reputation: 25755

You should put the database-file in the /assets-folder and copy it to the /databases-folder on first run. A tutorial on this can be found here.

However, if you only want to create the tables and some sample-entry's, you might want to use the onCreate()-method from the SQLiteOpenHelper to do so.

Upvotes: 2

DAS
DAS

Reputation: 696

Answering to the question : we can only extract the class files from the apk that we have got, we will not get the layout/xml files or any other files.

There are ways by which we can extract the class files from the apk.

Upvotes: 0

ykatchou
ykatchou

Reputation: 3727

Maybe you should store your data in the raw folder, you access it then :)

http://developer.android.com/guide/topics/resources/index.html

Upvotes: 0

Related Questions