简体   繁体   中英

Loading jquery-mobile page in android

我如何在我的android应用程序中加载jquery-mobile网页,以及我需要将我的jquery-mobile html文件放入我的android应用程序文件夹中,以便我可以访问它

Yes you can wrap your HTML pages inside the Android Application.

You can add your files into your assets folder and can show them inside the Android WebView . Read more about Android WebView and here an example . With WebView you gonna have to do something as below.

I assume wv is the WebView ID used in our layout xml

WebView wv= (WebView) findViewById(R.id.wv);
wv.getSettings().setPluginsEnabled(true);
WebSettings webSettings = wv.getSettings();
webSettings.setJavaScriptEnabled(true);
wv.loadUrl("file:///android_asset/myfile.html");

If you wanna manipulate the HTML String then you may do something as below

InputStream is = getAssets().open("myfile.html");
int size = is.available();

byte[] buffer = new byte[size];
is.read(buffer);
is.close();

String str = new String(buffer);
str = str.replace("old string", "new string");

Going further, there is a wonderful Java library that can do so much on HTML String (parsing, querying etc etc). Check out jSoup .

If you are interested in Hybrid apps (Web and Native) then check out PhoneGap , Appcelerator

Good luck.

Put the html file in assets folder of your application and then use webview to load the same.

 WebView wv= (WebView) findViewById(R.id.wv);
 wv.getSettings().setPluginsEnabled(true);
 WebSettings webSettings = wv.getSettings();
 webSettings.setJavaScriptEnabled(true);
 wv.loadUrl("file:///android_asset/myfile.html");

Try phonegap to deploy your html5 application into the mobile.

The /www folder contains a sample website.

You can try fiddling with it & see how they expose the mobile api into javascript. There is lots of help regarding that on their website.

You can either add the jquery mobile file along with the website or load it dynamically from their cdn. I would however prefer publishing it along with the application, but then it also means regular updating of the app in future.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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