简体   繁体   中英

Testing my android application on real device

I created a simple android application (With MySQL database connectivity logic in php) to register a new contact. When I ran the application to the emulator (using localhost IP Address as 10.0.2.2), it was working fine. Now I want to test it on my device and I am facing connectivity issue of localhost what should I do??

Here is my code:

@Override
protected String doInBackground(String... params) {
    String reg_url="http://10.0.2.2/mobile/register.php";
    String login_url="http://10.0.2.2/mobile/login.php";
}

Thanks in advance

First, make sure both your server and your device can establish a connection between each other (either they are in the same network, or the server is publicly accessible).

Then, check your server's IP address and get the port your server is running on. Use those when you establish a connection from your real device. The URL should look something like this: http://<server IP address>:<server port>/mobile/register.php .

You should look into adb reverse port forwarding . So, lets say you want your mobile's localhost:8888 to point to your local machine's localhost:8888, you can acheive it by using the following adb command:

adb reverse tcp:8888 tcp:8888

First parameter refers to the port on the device and the second on your computer.

adb reverse allows you to forward ports from your device to your host. Let me know if you have any doubts.

Refer to the following link for more info:

http://www.codeka.com.au/blog/2014/11/connecting-from-your-android-device-to-your-host-computer-via-adb

I think that the connection is established ,when i write my adresse IP from the phone i get the wamp Localhost[1]

but when i run the application and enter the user s name and password i get this (I think that is the description of the file login.php) [2]

http://i.stack.imgur.com/jSXXP.jpg // [1]

http://i.stack.imgur.com/cP8PB.jpg //[2]

i use this line to call the script php : String login_url="http://192.168.1.103:80/mobile/login.php";

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