android/h5 - android的部分机型不支持h5, 包括: oppo r9, 这样的旗舰机(android 7.0)

访问量: 91

如题.

这样的js代码,无法通过原生java代码 来调用.

    var that = this
    // 为了兼容ios, 我们不得不使用这样的语法糖.
    setTimeout(function () {
      getUserId = function() {
        console.log("userId为=" + that.$store.state.userInfo.id)
        return that.$store.state.userInfo.id
      }
      var iframe = document.createElement('iframe')
      iframe.style.visibility = 'hidden'
      iframe.style.width = '1px'
      iframe.style.height = '1px'
      iframe.onload = function () {
        setTimeout(function () {
          document.body.removeChild(iframe)
        }, 0)
      }
      document.body.appendChild(iframe)
    }, 0)

java代码:(在绝大部分android机上可以)

    public void getUserId() {
        webview.evaluateJavascript("getUserId()", new ValueCallback() {
            @Override
            public void onReceiveValue(String object) {

                String value = object.toString();
                SharedPreferences preferences = getSharedPreferences("SYYJID", 0);
                SharedPreferences.Editor editor = preferences.edit();
                editor.putString("USERID", value);
                editor.commit();

                Log.d(TAG, "getUserId value=" + value);
            }});
    }

订阅/RSS Feed

Subscribe

分类/category