简体   繁体   English

Webview无法呈现我的HTML5游戏

[英]Webview doesn't render my HTML5 game

I have a HTML5 game that has js files, css, jquery and .ogg files. 我有一个HTML5游戏,其中包含js文件,css,jquery和.ogg文件。 This game works fine on my website. 该游戏在我的网站上运行良好。 Now I want to have an Application in Android that download the game's files, store them somewhere (ex. App Data) and then load it in a webview to play game in offline mode. 现在,我想在Android中拥有一个应用程序,该应用程序可以下载游戏的文件,将其存储在某个地方(例如App Data),然后将其加载到Web视图中,以离线模式玩游戏。 I also enabled the javascript for my webview: 我还为我的webview启用了javascript:

myWebView.getSettings().setJavaScriptEnabled(true);

For testing my app, I put the game files in asset folder for now and load the index page of the game via: 为了测试我的应用程序,我现在将游戏文件放在资产文件夹中,并通过以下方式加载游戏的索引页:

myWebView.loadUrl("file:///android_asset/index.html");

After installing and opening the app, I just get a black webview. 安装并打开该应用程序后,我得到一个黑色的Webview。 Nothing is shown. 什么也没显示。 I want to know how I can make it work without any changes in my game files or scripts? 我想知道如何在不更改游戏文件或脚本的情况下使它工作吗? (because I want to have a web-service on my server that feed my application with the game files; the same files that is running on the website. Is it possible?!) (因为我想在我的服务器上拥有一个网络服务,该服务向应用程序提供游戏文件;该文件正在网站上运行。可能吗?!)

Thanks 谢谢

Try this, 尝试这个,

webView = (WebView) findViewById(R.id.webView);
webView.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return super.shouldOverrideUrlLoading(view, url);
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            super.onReceivedError(view, errorCode, description, failingUrl);
            Log.e("Error", description);
       }

   });

 String url = "POST_YOUR_URL_HERE";
 webView.getSettings().setJavaScriptEnabled(true);
 webView.loadUrl(url);

this may helps you. 这可能对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM