Are there any ways to embed a browser in Android app?

末鹿安然 提交于 2019-12-21 17:45:20

问题


I'm working on a project that needs to manage requests(html/javascript) and many more other things. I Used Chromiumembedded for windows. Now I need something like that for android.

I've searched about android programming and spent some time on Phonegap. As I know it opens a webview and have some javascript API for some device features like camera. So Phonegap is not going to help me.

I wonder if there is any way to embed Chrome or any other browser that can be embedded in an android app?


回答1:


Android has a WebView component that is basically a browser. You can place it anywhere in your application and you can enable JavaScript that is disabled by default. Supports HTML 5. I use it in production and fully recommend.

Unfortunately the 3.x versions have a bug not supporting string query that may be present inside URLs of some pages. In the bug website this issue shows as closed and fixed. I was even not aware about it as we use 4.1.0 for everything. The bug is already fixed with that release. For earlier versions, some workarounds are available here.




回答2:


Try android.webkit.WebView it's the equivalent of the iOS's UIWebView




回答3:


Use android.webkit.WebView

Set the view, for example:

WebView mywebview = (WebView) findViewById(R.id.webview);

and load the url of application:

mywebview.loadUrl("http://www.example.com");

or

mywebview.loadUrl("file:///android_asset/html_no_copy/test.html");

and for enable javascript in your application, set:

WebSettings webSettings = mywebview.getSettings();
webSettings.setBuiltInZoomControls(true);
webSettings.setJavaScriptEnabled(true);

Try and read the documentation: http://developer.android.com/reference/android/webkit/WebView.html



来源:https://stackoverflow.com/questions/14535346/are-there-any-ways-to-embed-a-browser-in-android-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!