Android Connection to php web services - php

I am new to android development. I have a module where I need to connect to a webservice via an android application. I have the web services in my localhost.
My question is: How to access them from my android application?
Tutorials on web says how to access the live web services.

First, both your computer and android device need to be in the same network,
If you use windows, go to cmd and type ipconfig /all
Find your computer's ip address
Then you will be able to access your server's from its ip address.
You can also check your firewall configuration if steps above don't work

i have did this before ,first of all , if you need to connect your android application with php service at localhost.following thing need following thing
Android Emulator on which application install
For SERVER -- WAMP or XAMP Server install on Local machine on which you are testing .
now host your php service in the www folder (in case of WAMP) or in the htdocs folder( in case of XAMP).
Now how to communicate between web service and android : as describe below
Now you have Envoirnment set now all you have to do is to follow this tutorial it will definatly resolve your issue .
http://www.androidhive.info/2012/01/android-login-and-registration-with-php-mysql-and-sqlite/

Related

Ionic on Mobile + MySQL Server + PHP (XAMPP) on PC

Hi I am currently learning Ionic Framework for hybrid mobile apps and I want to connect it to localhost server (XAMPP).
I am developing Ionic App on my PC through ionic start myApp blank and ionic serve.
I have a php file on my htdocs folder in XAMPP which serves as a server-side function to call/query in my MySQL database.
Well, it goes well in development saying that I am working Ionic App on my PC where XAMPP also installed.
But, when I try to ionic cordova build my Ionic App for debug deployment as APK file and install the APK on my Mobile device it is not working.
Well, I know the reason why.
because of the link in my codes: var link = 'http://localhost/api.php';
My questions:
How can I access the PHP file inside localhost server XAMPP
on my PC when my Ionic App is already APK and installed on my
Mobile Device?
Can I use my PC IPv4 address (saying that PC and Mobile are connected
on same WIFI) instead of localhost in var link?
I hope someone can give me a light on my dark room.
Thanks in Advance
I got a way on how to connect to my PC localhost web server.
First, I tried to connect to my WIFI IPv4 Address using the command ipconfig on cmd. And I tried to connect to it, then it was a success. I was able to connect my Mobile App to my PC Localhost web server (XAMPP). But the problem is, whenever the WIFI restarts, the WIFI IPv4 Address changes because of my WIFI DHCP(from what I read).
So, I came up with a another solution to that. I set my WIFI IPv4 address in my PC's Control Panel/Network and Internet/Network Connections and edit the WIFI IPv4 Address, instead of automatically assigned, I changed it to static. Whenever my WIFI device restarts, it does not change my PC WIFI IP address.
So, that's how my problem solved. But I think there will be a problem sooner when theres a same WIFI IPv4 address assigned to other connected device on the WIFI. But, it is okay for now. I am glad that I can access my MySQL database on XAMPP in my PC from my Mobile Device and able to query data.
Thanks. I hope this can solve the problem of other people who has similar problem of mine. Happy coding.

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

Wamp server connection

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?

wamp server working with emulator but not with any other android phone

I am newbie in android application and want to connect my android application with WAMP Server.For this i took reference of How to connect Android with PHP, MySQL. Things working great till i am using android emulator for debugging and running the application. But when i run same code from actual android device. I unable to connect WAMP server from android device.
Can you please tell me , how to access WAMP server from android device.
Please note :- My android device is not connected with PC or it is not in local area network.
In that case, you need to modify the bound address for the Apache server. Navigate to this directory:
wampinstallation\bin\apache\apache2.4.2\conf, then open httpd.conf in any text editor.
Ctrl+F to find the line where it says "Listen 127.0.0.1:80" (I'm pretty sure that's the default value), change that to "Listen 80". This will bind the Apache server to any network interface on port 80, making it accessible within your LAN.
After you've done that, you'll need to restart the Apache service via the Wamp tray icon.

Create and consume web service on local machine by using WAMP

Is it possible to create an environment on local machine( i.e. localhost) where we can create and consume web service using PHP?
Is there any flow to create a web service like environment on localhost?
I would like to create an environment on localhost for web services where local machines, on intranet, get connected to main server (here again it's local machine) and can consume web services.
Like on internet we have Web Servers from where we can create and consume web services, Can we do the same on localhost?
Edit:
I am using WAMP with
PHP 5.3 Apache 2.* MySQL 5Windows 8
It is easy to create a local web service. You will need a local web server (like IIS or xampp) to execute PHP locally.
Access you PHP application in your browser using http://localhost/<yourApp>.php and provide any webservice at a local URL as well, e.g. http://localhost/<yourService>.php. Your application can then access the webservice using the local URL.
This works both for REST or SOAP-style services.
EDIT: Your edit shows that you already set up a local environment to develop and test webservices. You should really be more specific in your question, maybe you are looking for a tutorial to create web services with PHP in genereal. If so, Google will be your best friend: https://www.google.de/#q=create+web+service+using+php+tutorial

Categories