I have installed XAMPP on my PC and I am writing android Java code to access the database in XAMPP as follows:
HttpPost httpPost=new HttpPost("http://10.0.2.2/mrs/authorization.php");
Here, 10.0.2.2 is only for android emulator (virtual device), it does not work for actual android device.
My question is: How can I make the actual android device able to connect the database server?
Instead of 10.0.2.2 you should use the local LAN ip address of your server pc. And your device should be in the same W(LAN).
No need for hotspots or other silly things.
Related
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 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
I'm confused..
I'm using XAMPP in my PC to create a local server that has a few php scripts that connects to a mysql database (also on my local server) and receive data and then send this data to my android application..
My question is about the android app, what IP should I give in the HttpPost to connect my PC and access the php script ?
Should I use the IP of my machine followed by the :port and the path to the php file or should I use only 10.0.2.2 and the path to the file ? I pretend to test this app in my real device, not in emulator.
If your android device and local computer are on same wifi router, you can run ipconfig (windows) or ifconfig (linux) to have the IP address of your computer on the network of the router (generally wtarting with 192.168.x.x)
You should use this IP address to connect from your Android device to your computer.
Note : Be sure your ports are open on your computer to let the phone connect to your computer
I'm trying to create android apps which able sending data through wifi connection to my laptop Apache Server and MySQL database. I use the samsung galaxy tab 10.1 as my mobile device. and the protocol i used is HttpGet or HttpPost. And i use XAMPP( with Apache& SQL) to do the server and process the php. But, due to android cannot detect adhoc network from laptop, i use Virtual Router ( for window 7) to create virtual access point and make the tablet able connect to my laptop. But the problem is:
In my apps (client-android), where the httpget or httppost to which url? localhost in my laptop- 127.0.0.1 or localhost in android 10.0.0.1? or the ip address of the virtual router?
So, if I want access from android to the localhost(laptop-Apache) to call the php to run? which port? which ip address /url that i need to put in android apps(httpget)? and do I need to modify anything in httpconfig for XAMPP?
Find out your Ip address in your laptop using ipconfig . use that address in the phone instead of 127.0.0.1.
as long as you know the I.P Address of the Computer with Apache on it , Since external MySQL access is quite tricky to set up id recommend sending JSON requests to your PHP scripts and getting the return value via Java then what you want to do with the output is upto you.
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