如何嵌入HTML code在Android应用程序?应用程序、HTML、code、Android

2023-09-05 09:09:32 作者:何必说从前

我正在写一个应用程序,为此我需要嵌入HTML对象的Andr​​oid应用程序,我也跟着在这里给出的教程:http://mobile.tutsplus.com/tutorials/android/android-sdk-embed-a-webview-with-the-webkit-engine/并修改了code因此,以下为code,但我得到一个白色的屏幕...有什么建议?

Hi i am writing an app for which i need to embed html object in the android app, i followed the tutorial given here : http://mobile.tutsplus.com/tutorials/android/android-sdk-embed-a-webview-with-the-webkit-engine/ and modified the code accordingly , following is the code, but i am getting a white screen...any suggestions ?

 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        WebView engine = (WebView) findViewById(R.id.web_engine);

    engine.getSettings().setJavaScriptEnabled(true);
    engine.getSettings().setPluginsEnabled(true); 
    engine.getSettings().setAppCacheEnabled(false); 
    engine.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); 

        String data = "<html>" +
                "<body>" +
                "bb"+
                "<object width=\"450\" height=\"300\" align=\"middle\"><param name=\"movie\" value=\"http://www.raaga.com/widgets/top10/widgettopten.swf?l=H&q=1\" /><param name=\"wmode\" value=\"transparent\"><embed src=\"http://www.raaga.com/widgets/top10/widgettopten.swf?l=H&q=1\" width=\"450\" height=\"300\" align=\"middle\" type=\"application/x-shockwave-flash\" wmode=\"transparent\"  FlashVars=\"gig_lt=1312323434023&gig_pt=1312325057958&gig_g=2\"/> <param name=\"FlashVars\" value=\"gig_lt=1312323434023&gig_pt=1312325057958&gig_g=2\" /></object>"+
                "gg"+
                "</body>" +
                "</html>";

        engine.loadData(data, "text/html", "UTF-8");
    }
}

这是我想要嵌入的对象是:

the object that i want to embed is :

<object width="450" height="300" align="middle"><param name="movie" value="http://www.raaga.com/widgets/top10/widgettopten.swf?l=H&q=1" /><param name="wmode" value="transparent"><embed src="http://www.raaga.com/widgets/top10/widgettopten.swf?l=H&q=1" width="450" height="300" align="middle" type="application/x-shockwave-flash" wmode="transparent"  FlashVars="gig_lt=1312323434023&gig_pt=1312326303531&gig_g=2"/> <param name="FlashVars" value="gig_lt=1312323434023&gig_pt=1312326303531&gig_g=2" /></object>

感谢 Nohsib

thanks Nohsib

推荐答案

把文件中的/资产目录中,你可以对文件进行访问:/// android_asset /目录

Put the file in the /assets directory, you can access it with the file:///android_asset/ directory.

而不是把HTML在$ C C资产文件夹$的是,你可以把静态数据文件,例如HTML及其相关CSS,图片和JavaScript文件,等等,那么你可以使用WebView.loadUrl().这已经不必在code与Java的String逃脱和繁琐的编辑的优势。您可以创建文件(S)分开,在你喜欢的web项目编辑器,然后复制并粘贴它们。如果您需要编辑该文件在运行时,你仍然可以从资产目录中加载该文件,仍然不必担心Java的String逃走了繁琐的编辑。然后应用编辑和传递给WebView.loadData().

Instead of putting the html in code the assets folder is where you can put static data files such as HTML and its related CSS, images, and JavaScript files, etc. Then you can use WebView.loadUrl(). This has the advantage of not having to be in code with Java String escapes and cumbersome editing. You will be able to create the file(s) separately, in your favorite web project editor, then copy and paste them. If you need to edit the file at runtime you can still load the file from the assets directory and still not have to worry about Java String escapes and cumbersome editing. Then apply the edits and pass to WebView.loadData().

要帮助调试这个问题落实WebChromeClient.onLoadResource并检查了控制台消息教程。

To help debug this problem implement WebChromeClient.onLoadResource and check out the console message tutorial.

不要忘了用PackageManager.getPackageInfo()检查闪存可用。如果它不是你可以给用户从市场下载的选项。

Don't forget to use PackageManager.getPackageInfo() to check if flash is available. If its not you can give the user the option to download it from the market.