Hi,
I am using webview in my app. WebView stores the downloaded pages in a cache
at /data/data/<pacakge-name>/cache/webviewCache/ . I didn't find any way to
make webview store its cache elsewhere, on SDCard for instance. But given
the large amount of webview cache that my app tends to accumulate over time,
I need to relocate this cache on SDCard.
I came up with a solution, that works well in my emulator. But I would like
your opinion about whether it violates any Android practices.
I came across many tricks that people try manually to relocate app's cache
storage to SDCard. They create a directory on SDcard and create a softlink
to it inside the app's package directory. Of course this is done manually
and needs root access.
I tried to do the same thing, but programmatically and only inside my app's
package directory. Since android (or IIUC Java for that matter) doesn't
support creating soft links. So I used java.lang.Runtime to workaround that
restriction. Essentially I use following three routines to move my
webviewCache back-n-forth between the phone and SDCard.
[code]
String WEBVIEWCACHE_SD_DIR = "/sdcard/readerscope/webviewCache";
String WEBVIEWCACHE_PHONE_DIR =
"/data/data/com.altcanvas.readerscope/cache/webviewCache";
public static void makeDir(String abspath)
throws ReaderScopeException
{
try {
Runtime.getRuntime().exec(new String[] {"mkdir", abspath });
} catch(java.io.IOException ioe) {
throw new ReaderScopeException(ioe.toString());
}
}
public static void createSoftLink()
throws ReaderScopeException
{
try {
Runtime.getRuntime().exec(new String[] {"ln", "-s",
WEBVIEWCACHE_SD_DIR, WEBVIEWCACHE_PHONE_DIR });
} catch(java.io.IOException ioe) {
throw new ReaderScopeException(ioe.toString());
}
}
public static void deleteSoftLink()
throws ReaderScopeException
{
try {
Runtime.getRuntime().exec(new String[] {
"rm", WEBVIEWCACHE_PHONE_DIR });
} catch(java.io.IOException ioe) {
throw new ReaderScopeException(ioe.toString());
}
}
[/code]
This scheme works in my 1.5 emulator. My questions are:
Will this hit any problem on a non-rooted phone?
Will this offend any (present/future) SecurityManagers that are monitoring
filesystem access?
Is it a bad practice to use absolute paths (even for directories that are
well within your package dir structure)? If so why?
Are there any plans to provide an API to customize WebView's cache location?
(Given that WebView's cache is perfectly local to the app and separate from
Browser cache, this shouldn't pose any security risks, I suppose).
Please let me know, what do you think.
Thanks,
Jayesh
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---