Issue
I have implemented context menu on WebView with Save image as an option. When user clicks on that option image is downloaded in an asynctask DownloadImage().
Inside doInBackground of DownloadImage asynctask I have code like this:
HitTestResult result = webview.getHitTestResult();
if (result.getType() == HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
// code to download and save the image
}
This was running fine on all android versions upto 4.4. Now I changed the targetSdkversion from 17 to 19 and my app start crashing on android 4.4 when clicking on Save image option. Checking crash logs I get runtime exception on the line HitTestResult result = webview.getHitTestResult();
. But it still continues to run fine on Android 4.4 if I set targetSdkVersion to 17 again.
I think it is somehow related to new Android 4.4 (API level 19) that is based on Chromium. More specifically related to this:
http://developer.android.com/guide/webapps/migrating.html#Threads
Now I am wondering wether I should set targetSdkversion to 17 and release the build or do some other workaround to fix this issue ?
And what is the best solution for this ?
Solution
Like the docs say: the solution to this is to only call WebView methods on the UI thread. The exception is intentional - new applications should not call WebView methods from background threads. The preferred solution is to set targetSdk to 19 and update your code.
In your case it looks like you could just get the value of webview.getHitTestResult().getType() from the 'Save image' menu option handler (which runs on the UI thread, right?) and save that as a field on your AsyncTask.
Answered By - marcin.kosiba
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.