简体   繁体   中英

Android Studio connecting to localhost in mobile

I just wanted to ask how to connect to the localhost when the app is installed in mobile? I tried installing the apk of the android app in my mobile phone instead of the emulator of android studio. My app has a login and register activity. In the emulator, I'm able to register and login while I cannot register and login using my phone. Thanks in advance for the answer!

There are a lot of answers exist, but in simple follow the steps below.

  1. First try to connect both your pc and mobile devices in the same network .
  2. Then find the ip of your pc (run ipconfig in command prompt if you are using a pc).
  3. Place this ip as your base url in your app and use register/login endpoints as per your need.

    For eg: http://your.ip.here/register.php like this > ( http://192.168.0.2/register.php )

  4. Now run the app, it'll connect to the above said ip.

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