6

This is similar to other questions already asked in the past, but with a new twist. The notification for WebView's capturePicture() completion is onNewPicture, but the latest documentation says that the picture returned in this will always be null from API 18 onwards (Android 4.3).

WebView.PictureListener

So far, I've checked that it still works on Android 4.0.3 (and trying to use the captured image fails unless I wait for the notification).

What are we supposed to use as a replacement? Will the picture be returned immediately in onPageFinished or when WebChromeClient's progress notifies 100%?



Update


API-18 (Android 4.3) appeared on the SDK a couple of days ago. onNewPicture still sends the captured picture on the emulator. Unfortunately I have no actual device with Android 4.3.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Indivara
  • 735
  • 1
  • 7
  • 19
  • We are facing the same problem. On a Samsung Galaxy S4, the picture was not yet ready when calling capturePicture in onPageFinished(). On the other hand, the PictureListener.onNewPicture() worked, although the docs state that it should not work. We're still looking for a non-drepecated alternative. – Daniel Albuschat Jul 31 '13 at 13:44
  • I'm not sure if that will work having this flow: DummyService bound to activity that will do the capturing(queuing is great) -> WebView is passed to the service -> Service waits for capturePicture() -> Take the Picture object -> Send it back to activity (via BroadcastReceiver, Handler, Messenger, whatever). But if you look a the source the method `checkThread()` should pass. http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.3_r1/android/webkit/WebView.java#WebView.checkThread%28%29 – Nikola Despotoski Aug 01 '13 at 02:02

1 Answers1

1

It actually depends on the targetSdkLevel of your app. For compatibility, onNewPicture still sends the picture if the target level is < 18 (JB MR2).

The preferred approach for capturing WebView image is to cause it do draw on a Canvas provided by you, see for example Which can replace capturePicture function

Community
  • 1
  • 1
Mikhail Naganov
  • 6,643
  • 1
  • 26
  • 26