how can i connect an android app (on my phone) to a php server (EasyPHP) that i am running on my machine (localhost). Are there any tutorials out there that document this.
I need to test the app on an actual phone not an emulator (because the emulator contains bugs for certain activities). Any help would be great!
If you connect on your Android with WiFi, you will be in the same network, then you can access PHP server via your machine's IP address.
Ys you connect to the php script...
Android allows you to sent data in GET and POST method..
I found a useful tutorials about this: Android phpMysql connection
Related
I made an ionic app with a connection to MYSQL using a PHP API which I put on another computer on Xampp, using it as a remote server in the same network, when I run it on the computer with ionic serve , it works fine but when I generate the APK, it wont connect to the BD, even tho Im on the same network, does someone knows any way around this?
this is how it looks on the desktop
and this is how it looks on the cellphone
What I would conclude is that it connects to the nodejs server ("ionic serve") to load the assets from there but it cannot load data from the php/mysql API.
How did you reach the conclusion that MySQL is the problem? I mean your frontend (angular) does connect directly to MySQL right?
Hint: check your settings within ionic when you call the API -- it should point NOT to localhost/127.0.0.1 but to your computer's network IP. Apache should also be "open" to connections from "outside":
see here: Accessing localhost (xampp) from another computer over LAN network - how to?
I had the same problem in the past, it is because when you run the application on your pc it is working on localhost, just like your backend. When you run your application on a mobile device, it does not have access to your pc using localhost to access the backend.
In this case you must set the IP that your pc has on your local network as the backend address and in this way your mobile application can access it
I'm trying to get JSON data from a PHP file (Apache/XAMPP) in localhost to Android using only a USB cable. The Android device is offline. Is it possible? Someone suggested using okhttp3 but I can't figure out how to.
If not already tried, Try running the app from emulator first but with the IPv4 address from ipconfig(command promt).use the ipv4 address instead of "Localhost:8080" use "Localhost:" in your code.
I have android program to display the sensor data and on button click it will send to local MySQL database running with PHP as backed in wamp server.its working properly.to connect to database i have given local host or local IP address of the system which is running. now i want to send the data to same database on button click with any network connected ? what should i do ? I even tried change allow access to all edit alias in wamp server but unable to connect. so any one suggest what to do?
thanks in advance
Make sure your android app and the computer on which your php code is running are all in the same network. To do this all you can do is create wifi hotspot using one of the devices and connect the other to the same wifi (Create hotspot in your mobile, which is running the app and connect your computer to the same wifi hotspot. Next open command prompt and execute ipconfig. Use the IP address that you got when you connected your computer to mobile hotspot).
OR
You can host your backend code on some servers and use the IP address in your android app(This is more as useful as you can use your android app from any network)
I have developed an android app that connect mysql database using php. when making https request to scripts php from other computers located on the same local network no problem, but when trying to request the same scripts from my android phone it gives tcp errors.
There is however a far better solution. You can access your host machine with the IP address "10.0.2.2".
This has been designed in this way by the Android team. So your webserver can perfectly run at localhost and from your Android app you can access it via http://10.0.2.2:8080.
What error do you get? If it's a forbidden error then it could be your httpd config file blocking your android. Can you tell from the error whether the problem is in your android application or a network connectivity error?
I have installed WAMP on Computer whose IP is 192.168.1.1 and Printer is connected to same Computer
using USB.
And have configured WAMP so that my Android Device can access Server (WAMP) through WiFi,
i.e. http://192.168.1.1/myproject/print.php
My Android device ip is 192.168.1.2
What i want is to print data which is fetched from DB using PHP file, through Android device directly.
Please help me solving this issue.
You could start by looking at the docs for printing
http://developer.android.com/training/printing/index.html
However you should at least attempt to create an application and post this code to Stackoverflow for better feedback