Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebView and localhost

Tags:

I am getting google.com inside my WebView, but am not getting my localhost in that. Can anybody help me?

like image 461
Jithin Avatar asked Dec 02 '10 15:12

Jithin


People also ask

What is WebView used for?

Android WebView is a system component for the Android operating system (OS) that allows Android apps to display content from the web directly inside an application.

How is WebView different from browser?

Simply put, Android WebView allows apps to display web content, without having to open a web browser. Up to Android 6, WebView was a system service. Then, with Android 7.0, Google incorporated that functionality into the default Chrome Browser.

What is WebView explain with example?

WebView is a view that display web pages inside your application. You can also specify HTML string and can show it inside your application using WebView. WebView makes turns your application to a web application. This method specifies the WebView has a back history item.


2 Answers

Use 10.0.2.2 instead. This is a special ip address that the emulator routs to local host on your dev machine. assuming that emulator and the webserver are running on the same machine.

like image 52
Jithin Avatar answered Sep 27 '22 21:09

Jithin


Make sure you are loading WebView with full Urls.

http://www.google.com http://10.0.2.2/ 

and not:

www.google.com google.com 

All of these will work while using Browser, but you must supply a full valid url for WebView. Banged my head against the keyboard for an hour figuring that out.

If you're having connectivity issues in the emulator, try overriding the dns in the build path.

Window > Preferences > Android > Launch Default emulator options: -dns-server 8.8.8.8 
like image 20
Gaʀʀʏ Avatar answered Sep 27 '22 20:09

Gaʀʀʏ