Reputation: 28902
I've been using this method to gain access to internet from my Android emulator
emulator -http-proxy <<proxy-name>> -avd <<avd_name>>
It works but is that the best way to do it? It just doesn't feel right that I need to open the emulator from command line and can't just do it from Eclipse or something.
Can't seem to find an internet option on the "AVD Manager" either.
Upvotes: 46
Views: 118990
Reputation: 5323
Hi me also faced same issue , solved using below steps:
Add internet permission in your android application
Check the manually your default application is able access internet or not if not its problem of your emulator , check in your internet connection in your pc
try below method to connect net in your pc
try explicitly specifying DNS server settings, this worked for me.
In Eclipse:
Window>Preferences>Android>Launch
Default emulator options: -dns-server 8.8.8.8,8.8.4.4**
check : check if you are using more than one internet connection to your pc like one is LAN second one is Modem , so disable all lan or modem .
Upvotes: 3
Reputation: 1
I've seen various suggestions how code can find out whether it runs on the emulator, but none are quite satisfactory, or "future-proof". For the time being I've settled on reading the device ID, which is all zeros for the emulator:
TelephonyManager telmgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); boolean isEmulator = "000000000000000".equals(telmgr.getDeviceId());
But on a deployed app that requires the READ_PHONE_STATE permission
Upvotes: 0
Reputation: 1
You can do it using AVD Manager, choose Tools -> Options. Set HTTP Proxy Server to 8.8.8.8,8.8.4.4
The emulator will be connected.
Upvotes: -2
Reputation: 395
If someone have a Internet Permission in AndroidManifest and still have a problem with Internet Connection, maybe that will be helpful: Android - Fixing the no internet connection issue on emulator.
I followed steps from that website, and everything works for me. The most important:
That is my first post, so I hope it will be helpful.
Upvotes: 1
Reputation: 1227
delete the existing one and recreate the emulator. The machine(windows/mac) should have internet access,and android emulator gets internet access by default.
Upvotes: 1
Reputation: 155
for the records since this is an old post and since nobody mentioned it, check if you forgot (as I did) to set the android.permission.INTERNET flag in AndroidManifest.xml as, i.e.:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.webviewdemo">
<uses-permission android:name="android.permission.INTERNET"/>
<application android:icon="@drawable/icon">
<activity android:name=".WebViewDemo" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Upvotes: 7
Reputation: 31
It was setting the DNS that did the trick for me. If you are using the Eclipse or Netbeans plugins, you can set it through Default Emulator options, or Emulator Options respectively. You can also use set it from the command line if you start your emulator from CLI. In all cases, the option is "-dns-server x.x.x.x,x.x.x.x" without the quotes. There is no option in the ADB gui to permanently associate the option with your virtual device.
Upvotes: 3
Reputation: 11540
You could also try explicitly specifying DNS server settings, this worked for me.
In Eclipse:
Window>Preferences>Android>Launch
Default emulator options: -dns-server 8.8.8.8,8.8.4.4
Upvotes: 58
Reputation: 145
Add GSM Modem Support while creating AVD in your virtual devices from Android SDK and AVD Manager...
Upvotes: 4
Reputation: 1773
On a slightly different note, I had to make a virtual device without GSM Modem Support so that the internet on my emulator would work.
Upvotes: 0
Reputation: 51
-http-proxy can be set in eclipse this way:
Upvotes: 5
Reputation: 16367
By default, you should be able to toggle the Internet access to your emulator with F8 (on Windows) and Fn + F8 (on Mac OS X) - I think F8 also works for Linux, but I'm not 100% sure.
With this shortcut, you get the ACTION_BACKGROUND_DATA_SETTING_CHANGED dispatched.
Hope that helps.
Upvotes: 23