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.
Related
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.
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.
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 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