0

In a native Android App, I have various Products. Every product has related descriptive product information in html files (index.html, images, detail pages, javascript).

When a product is selected, i want to show the related html content in a WebView. I do not want to permanently embed HTML files in the app itself.

Approach: I am planning to download the Product HTML bundles(zip?) on demand. So if you select Product X, then its HTML zip will be downloaded and used.

  • To download or not?
    The reason to download the HTML files, is that they will render faster from local directory, but i am open to render it directly from a server, if that can be fast enough too.

(I also want to protect the HTML files, so that no one else can point to them except my app itself)

  • Download location
    Which is the best location to download these HTML zip content, and unzip there?

  • How can i show HTML files from local dir?

Is there a better approach?

Tajkia Rahman Toma
  • 472
  • 1
  • 5
  • 16
Jasper
  • 8,440
  • 31
  • 92
  • 133

1 Answers1

0

I do not want to permanently embed HTML files in the app itself

Download the .zip file on first run and unzip in the app directory of the application so you won't have to download it every time.

To download or not

You are right, downloading html files from server on demand is not a good approach when you have large number of files. That means you are making hit on server for every html file. You can also face time delay or connectivity issues.

Download location

All apps (root or not) have a default data directory, which is /data/data/<package_name>.By default, the apps databases, settings, and all other data go here. If an app expects huge amounts of data to be stored, or for other reasons wants to "be nice to internal storage", there's a corresponding directory on the SDCard (Android/data/<package_name>).

Apart from that, all apps can store data anywhere on the SDCard, as there are no restrictions -- and many apps do so. They can use directory names freely (and they again do), which is what often makes it hard to decide what all that "junk" on the card is intended for, and what of it can be deleted.

Reference: Where Android apps store data?

How can I show HTML files from local dir?

You can access the default directory like:

PackageManager m = getPackageManager();
String s = getPackageName();
try {
    PackageInfo p = m.getPackageInfo(s, 0);
    s = p.applicationInfo.dataDir;
} catch (PackageManager.NameNotFoundException e) {
    Log.w("yourtag", "Error Package name not found ", e);
}

Reference: Get Application Directory

Community
  • 1
  • 1
Shahzeb
  • 3,696
  • 4
  • 28
  • 47
  • From Lollipop, apps can't write anywhere in the SD Card. If so, user permissions are to be obtained by SAF(except for app specific directory in the SD Card). – somesh Oct 05 '15 at 10:58