0

I have built an Android application using the emulator to test. It connects to localhost to get and send data which works well. Now I want to try that application on my mobile device. I have read that I have to:

  1. connect my computer to my router network
  2. connect my mobile to my router network
  3. go to the code and replace the 10.0.2.2 with the IP of my computer

Am I right? If so, is that computer's IP the IP that connects my computer to internet?

2 Answers 2

2

If you are developing in Eclipse, all you have to do is:

  1. Connect your device to your computer with a USB cable
  2. Right click on the root of your app
  3. Select "Run As" > Android Application
  4. If your device is connected, it should automatically run

Note sometimes you have to select whether you run on your connected device or on your emulator, but a window will display your options and your just select one.

Simple as that.

Sign up to request clarification or add additional context in comments.

8 Comments

i don't want to connect using cable, i want to connect using local network
Can I ask why you don't want to connect using a cable?
my graduation project is a server/client project, i will test the project using 5 mobile devices
and i tried your way but eclipse run the application on emulator, not on mobile, have i make any configurations?
Right click on the Root (after you connect via cable) and select "Run As" > Run Configurations, click on the Target tab, then select "manual". If your device is connected, you will get a prompt asking you to connect either to your device or emulator when your follow the above steps. If that doesn't work your device might not be recognized by your computer. To test that, go into DDMS and see if your device is recognized. If not, try a different cable or check your connection settings.
|
1

You are correct, when you simply connect to your local router you can get to your localhost by changing the configuration to point to: "http://10.0.2.2:8080"

I found the other ways to be very tedious

http://juristr.com/blog/2009/10/accessing-host-machine-from-your/ http://developer.android.com/tools/devices/emulator.html#emulatornetworking

2 Comments

i will check your solution after i finish connect my device to my computer, thank you
Not really MY solution, it was a solution that the android engineers developed. :) Anyways, happy programming and I hope it works out for you as it did for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.