android sensor programe to send data to local database - php

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)

Related

Localhost and Android Connection

Let's say I'm developing application on my laptop. I have connection to the localhost, and created database. Will I be able to store, or extract data when I run my application on my phone? The phone is not connected to the laptop.
Yes:
Your phone and laptop connected to same LAN (minimal example: set your phone as router with mobile hotspot and connect your development laptop to it).
In other words simply connect the phone and PC running the server to the same local network.
if you have puplic ip you can even let others test your app and connect to your pc as server (preferred static but dynamic will work as well but you have to monitor it and change it in your app every time it changes but most of the time it stays for hours if its not a moving mobile).
Edit:
For php apps you can install a php server in your android phone like Palapa Web Server (tested) and then in your app just make your calls to local address.

How can i connect my android device (not emulator) to wamp server?

I want to make an entry into my MySQL database. I am using WAMP server. I have successfully created database entry into my MySQL database using my Android emulator's app but I can't done it by using my external physical Android device. I'm using my IPv4 address (http://192.168.42.206/pankaj/v1) to connect with wamp server. So how can I connect my Android device (not emulator) to WAMP server?
Start Wamp Server;
Click on the icon and select 'Put Online' option.
It should work now.

Which ip i should put on the url of my php request?

I am developing an application which basically starts with registration system using the wampserver to connect to mysql database through localhost/phpmyadmin as a back-end and android client using genymotion emulator as a front-end and both front and back end communicates through php/mysql API.
I have followed different tutorials to achieve all this but since none of them actually used genymotion I am missing the part of which IP, I should put for this mechanism to follow smoothly.
when you use emulator on you pc , your emulator will connect to virtual network interface that you can change it ....
you should check emulator network interface and enter your pc ip in that network interface ...
i attached a picture of setting of my emulator and you can see my emulator use my wifi network interface .... thus i should insert my computer ip address of wifi network interface
finally you should get your pc ip as network interface that your emulator connected to that and use that ip in emulator for connect to your webserver in your pc.....
in Wampserver, you can not access to apache from outside ...
you should change apache config (httpd.conf) and make access for outside connection ...

Android ip to connect to PC

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

connect app to php server on localhost

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

Categories