简体   繁体   English

将 android 应用程序连接到我的本地服务器

[英]Connecting an android app to my local server

I am new in Android and I just got some tutorial on how to use it and sqlLite.我是 Android 新手,我刚刚获得了一些关于如何使用它和 sqlLite 的教程。

The problem:问题:

I have a MySQL server on my local PC and I am using Android studio to develop my Android application.我在本地 PC 上有一个 MySQL 服务器,我正在使用 Android Studio 开发我的 Android 应用程序。 My application will have a listing of pharmacies in my database, and the pharmacies are in the server database.我的应用程序将在我的数据库中列出药房,而这些药房位于服务器数据库中。

How can I connect to MySQL from Android to my local PC and get the pharmacies' details from the database?如何从 Android 连接到 MySQL 到我的本地 PC 并从数据库中获取药房的详细信息?

I created a Java class for the pharmacies in my application and an http request function to get the list from the database and return a json object, but I couldn't connect to the local database.我在我的应用程序中为药房创建了一个 Java 类,并创建了一个 http 请求函数来从数据库中获取列表并返回一个 json 对象,但是我无法连接到本地数据库。 Should I put the connection string as the IP of my PC?我应该把连接字符串作为我电脑的 IP 吗?

Can someone provide a tutorial for me?有人可以为我提供教程吗? I couldn't find a replica of my problem on the internet.我在互联网上找不到我的问题的副本。

To connect your android app to your local server, your base url has to be the ip of the computer with the local server eg.要将您的 android 应用程序连接到您的本地服务器,您的基本 url 必须是具有本地服务器的计算机的 ip,例如。

String baseUrl = "http://192.0.2.120:8080"; //Java

              //or

val baseUrl :String = "http://192.0.2.120:8080" //Kotlin

The baseUrl is passed into your retrofit or whatever http client you are using baseUrl 被传递到您的改造或您正在使用的任何 http 客户端

Please note that the android device and the local machine should be connected to the same network.请注意,android 设备和本地机器应连接到同一网络。

Try this!!!试试这个!!!

localhost/yournamefile/.....

Or see tutorial或者看教程

http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/ http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/

Hope.希望。 It will help you !!!!它会帮助你!!!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM