简体   繁体   中英

Which ip adress to type when running android app on real device?

In my android app users should type their personal datas and it should be sent to remote database. In order to do that I have created PHP script and AsyncTask class and all the other necessary things. When I run the app on localhost, everything works perfectly.

Here is the line when PHP script is called from android app

insert.execute("http://10.0.2.2/registerApp.php");

My question is, what IP adress should I type instead of 10.0.2.2 in order tu run my app successfully on real device, not on emulator ??

I am confused, first thing that crossed my mind was that I should type IP adress of my phone device where I am gonna test the app, but then I thought what is gonna happen if I take some other phone device which has different IP adress?

My question is, what IP adress should I type instead of 10.0.2.2 in order tu run my app successfully on real device, not on emulator ??

The IP address of the 'server' hosting the PHP script.

The address 10.0.2.2 (when used on an emulator) is translated to be the localhost address of the PC which the emulator is running on.

If you take the emulator out of the equation, and assuming you're connecting to the 'server' using wired or wireless connection, then you need to use the actual IP address of the PC.

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