Is there a listener for when the WebView displays it's content?
I successfully used Richard's answer with a PictureListener for a few years, but I no longer recommend this as the best solution.
This is for two reasons:
- webView.setPictureListener and PictureListener are both deprecated.
- Using this listener will cause the WebView to allocate a new Picture often. This allocation is expensive and this can have some significant performance impacts or even cause native crashes on JellyBean MR1.
Instead I recommend creating a subclass of WebView and overriding invalidate() like so:
@Override
public void invalidate() {
super.invalidate();
if (getContentHeight() > 0) {
// WebView has displayed some content and is scrollable.
}
}
If you still want to use the PictureListener method, you will get better performance if you setPictureListener back to null after you are done with it.
WebView - listener when scrolling is done?
Not sure there is anything in the standard WebChromeClient or WebClient interfaces that will let you do that. You will probably need to register a custom javascript object and then use a callback in the page (unless I'm wrong there are DOM level events you can listen for) to notify you when the scroll is done.
Android Webview: Detect when rendering is finished
Finally I got the very detailed for this problem. This explains why it always returns null bitmap.
Every change in my app are triggered by a user action so I came up with a modified version that only trigger invalidate() after a touchEvent
Thank for all your help.
Android WebView renders blank/white, view doesn't update on css changes or HTML changes, animations are choppy
Android Webview : detecting when page has rendered
Rendering of a WebView can take a long time for long documents, and indeed onNewPicture has been deprecated since API 12 (Honeycomb 3.1) and returns a null picture since API level 18 (Jellybean 4.3).
I have tested for API level 17 (JB 4.2), and it still works fine. Probably works fine in API 18 too if you don't need the actual Picture
details.
Please this issue on the issue tracker so we can get a non-deprecated replacement.
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR1) {
PictureListener pictureListener = new PictureListener() {
@Override
@Deprecated
public void onNewPicture(WebView view, Picture picture) {
Log.i(TAG, "Picture changed!");
}
};
webView.setPictureListener(pictureListener);
}
Related Topics
Get Uri of .Mp3 File Stored in Res/Raw Folder in Android
Method Not Found Using Digestutils in Android
Using Global Exception Handling on Android
How to Find and Turn on Usb Debugging Mode on Nexus 4
How to Start/ Launch Application at Boot Time Android
Comparing Two Drawables in Android
Android - Nullpointerexception on Searchview in Action Bar
How to Use Custom Font with Webview
Android - Application (Apk) Maximum Size
How to Globally Force Screen Orientation in Android
How to Change the Default Icon on the Searchview, to Be Use in the Action Bar on Android
How to Customize Share Intent in Android
Android Design Support Library for API 28 (P) Not Working
Bind/Unbind Service Example (Android)
Recyclerview Itemclicklistener in Kotlin
What Is the Role of Content_Main.Xml in Android Studio 1.4