使用从http://www.gutterbling.com/blog/synchronous-javascript-evaluation-in-android-webview/借鉴的技术,我们已成功在我们的应用程序中实现了许多功能,允许我们的Android应用程序同步从中获取数据Webview.
这是来自gutterbling的例子:
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import android.content.Context;
import android.util.Log;
import android.webkit.WebView;
/**
* Provides an interface for getting synchronous javascript calls
* @author btate
*
*/
public class SynchronousJavascriptInterface {
/** The TAG for logging. */
private static final String TAG = "SynchronousJavascriptInterface";
/** The javascript interface name for adding to web view. */
private final String interfaceName = "SynchJS";
/** Countdown latch used to wait for result. */
private CountDownLatch latch = null;
/** Return value …Run Code Online (Sandbox Code Playgroud)