Search in sources :

Example 1 with WebMessage

use of android.webkit.WebMessage in project cw-omnibus by commonsguy.

the class MainActivity method onSensorChanged.

@Override
public void onSensorChanged(SensorEvent sensorEvent) {
    float lux = sensorEvent.values[0];
    jsInterface.updateLux(lux);
    String js = String.format(Locale.US, "update_lux(%f)", lux);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        wv.postWebMessage(new WebMessage(jsInterface.getLux()), Uri.EMPTY);
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        wv.evaluateJavascript(js, null);
    } else {
        wv.loadUrl("javascript:" + js);
    }
}
Also used : WebMessage(android.webkit.WebMessage)

Example 2 with WebMessage

use of android.webkit.WebMessage in project cw-omnibus by commonsguy.

the class MainActivity method initPort.

@TargetApi(Build.VERSION_CODES.M)
private void initPort() {
    final WebMessagePort[] channel = wv.createWebMessageChannel();
    port = channel[0];
    port.setWebMessageCallback(new WebMessagePort.WebMessageCallback() {

        @Override
        public void onMessage(WebMessagePort port, WebMessage message) {
            postLux();
        }
    });
    wv.postWebMessage(new WebMessage("", new WebMessagePort[] { channel[1] }), Uri.EMPTY);
}
Also used : WebMessagePort(android.webkit.WebMessagePort) WebMessage(android.webkit.WebMessage) TargetApi(android.annotation.TargetApi)

Aggregations

WebMessage (android.webkit.WebMessage)2 TargetApi (android.annotation.TargetApi)1 WebMessagePort (android.webkit.WebMessagePort)1