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);
}
}
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);
}
Aggregations