Android ip to connect to PC - php

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

Related

android sensor programe to send data to local database

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)

ios access localhost from real device

I have a local php(Laravel) server. I can access the domain "mydomain.dev" from an simulator but it does not work when I try to access it from a real device. I have the app running with the device connected to the same wifi network but it still does not work.
Open your command prompt/terminal
Type
windows ipconfig
linux ifconfig -a or ip addr show
write your IPv4 adress
exemple (windows)
Then Run your server php artisan serve or whatever you are using (wamp/laragon or easyphp ..etc)
then go to your browser in your phone and navigate to mydomain.dev
This should work.
Please try to use IP address instead of mydomain.dev. When running on a real device, it will search dns server to look up mydomain.dev. If the dns server can't recognize this url, your device can't open it.

How to Connect Android App with a Local Web Sever using wifi

Android app Connectivity with Local Web Server
I want to connect my android app with local web server to access my php files and store data into web server database.
I also tried to use free hosting web site 000webhost.com but their database didn't provide me InnoDB DB engine, They have MYISAM which doesn't provide foreign key property...
please suggest me any solution for this issue...??
1、you can connect to you local web server through 127.0.0.1/yourproject/path
2、check you ip, like 192.168.0.110 etc.
3、try to access 192.168.0.110/youproject/path in your phone browser.
if you can access in you browser, that's your testing address
If using windows get your server ip by running:
ipconfig
in the Command Prompt. Then search for IPv4 that is your server ip;
If Using Linux Use:
ifconfig
in terminal. Then get inet addr field in wlan0.
Now you have ip address of server.
Use it as: http://yourserveripadress

Android phone accessing database installed on other PC

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.

How to connect android client to the localhost of Apache server (php) inside my laptop?

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.

Categories