网络中的 firebase google 身份验证不适用于 android 应用程序 webview

Md *_*lam 3 javascript android android-webview firebase-authentication

我正在创建一个使用 firebase google 身份验证登录的网站。它在所有浏览器中都运行良好。但是当我在我的应用程序中添加这个网站作为 webview 时它不起作用。

显示此错误的网站:

此应用程序运行的环境不支持此操作。“location.protocol”必须是 http、https 或 chrome-extension,并且必须启用 Web 存储。

这里有一些代码如下:

JavaScript 代码:

function login(){
    console.log('login called');
    function newLoginHappend(user){
        if(user){
            model_questions(user);
        }else{
            var provider = new firebase.auth.GoogleAuthProvider();

            firebase.auth().signInWithPopup(provider).then(function(result) {
              // This gives you a Google Access Token. You can use it to access the Google API.
              var token = result.credential.accessToken;
              // The signed-in user info.
              var user = result.user;
              // ...
            }).catch(function(error) {
              // Handle Errors here.
              var errorCode = error.code;
              var errorMessage = error.message;
              // The email of the user's account used.
              var email = error.email;
              // The firebase.auth.AuthCredential type that was used.
              var credential = error.credential;
              // ...
            });
        }
    }

    firebase.auth().onAuthStateChanged(newLoginHappend);
}

window.onload = login();
Run Code Online (Sandbox Code Playgroud)

网页视图代码:

   WebSettings webSettings =webView.getSettings();
   webSettings.setJavaScriptEnabled(true);
   webView.setWebViewClient(new WebViewClient());
   webView.loadUrl("https://mahmud-cse16.github.io/CBAP_Handout/");
Run Code Online (Sandbox Code Playgroud)

有什么方法或技术可以解决这个问题吗?如果您有任何想法,请与我们分享。

谢谢

Jit*_*ath 5

尝试为 webview 启用 DOM 存储

WebSettings webSettings = myWebView.getSettings();
webSettings.setDomStorageEnabled(true);   // localStorage
Run Code Online (Sandbox Code Playgroud)

设置是否启用 DOM 存储 API。默认值为 false。

Android 开发者参考