问题描述
在我的应用程序中,我使用的是 Webview。所以我想监控网络变化,即离线或在线情况。基于此状态,我想通过以下代码在后台更新/发送一些数据到 javascript 代码。
const [counter,setCounter] = React.useState(1);
function handleIncrement (counter){
setCounter(counter => counter + 1)
}
function handleDecrement (counter){
if(counter>1){
setCounter(counter => counter - 1)
}
}
如果应用程序在后台或关闭,我想监控这些网络变化,并调用上面的代码在后端设置一个值。
我编写了一个 broadcastReceiver 代码来检查网络变化。但是如何始终在后台运行它以及如何从那里调用 webview.evaluate()。
mWebview.evaluateJavascript(".object.setStatus(" + status +")",null);
我的应用只支持版本 26 到 30。
提前致谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)