Developing android application with a development web service - android

I'm currently building an Android Application and an accompanying Web Service. Right now I'm having some trouble figuring out the best way to configure the Android Application to know where the Web Service is. When I use the emulator and I'm running a local dev version of the web service, I manually tell the Android Application that the web service is hosted at "10.0.2.2". This works well for the emulator, but not for a physical device. I'm able to access it, via my phone, over the LAN using it's IP address, so actually accessing the web service is not the problem. It's just a pain to have to change the IP when I want to run it on my phone. Is there some configuration I could use to make this task easier?

I found out that you could do something similar to what I was asking using some gradle.
http://jeremie-martinez.com/2015/05/05/inject-host-gradle/
This post shows you how to add the ip address of the development computer to the code at compilation time.

Related

Running an HTTP Web Application on Android

I have a scenario where I should connect and disconnect to several WiFi endpoints from my web application and at the same time expose some REST API's. Since I come from a JVM background, I started writing a Java web application using Spring Boot and when I started to try writing WiFi connections / disconnections, I realized that it is not so easy and I had to do some ugly hacks. So I ditched the JVM and I thought that I could explot Android for this and this API from Android is exactly what I need:
https://developer.android.com/reference/android/net/wifi/WifiManager.html
I now have a Android device and this device would run as my primary server where I would like to run a Web Application that would eventually serve REST styled end points and at the same time manage my WiFi connections. I want to be able to use the Android SDK with which I could connect and disconnect to several WiFi networks, but I'm not sure as to how I could have a HTTP server that runs on Android where I can implement my classical CRUD style web application like I do in Spring Boot.
Any suggestions?

Is there a way a browser can directly talk to android application?

It seems there is an initiative from Google to directly send the map directions from Chrome to Android device. I was wondering is there a way browser can communicate with directly an Android application, where the Android device is connected to the system by Cable. This will be helpful in some scenarios where the user does not have access to Wifi, and he wants to download the data to the mobile phone.
You use the Android Intent invocation that is available in the Android browser and demonstrated in here.
The problem that you will face is that not every app supports the ability to be opened from the Web Browser. This also relies on the fact that you are on the same machine and doesn't solve your "cabled" issue. You will also have to know how to exactly integrate with these Android apps, and that is not something that they often expose.
For a few reasons there is often no direct access to local files/devices from inside a browser. When cabled, you can forward a tcp port of the android system to local system, using Android Debugging Bridge(adb).
So you can send some commands/data to the device by setting up an application in android who listens to particular tcp port, and forward the port to local system. Then all access to the local port is forwarded to this application. Then with such techniques like jsonp, your browser can communicate with your device.

Android Emulator communication from different machines

I've referred the developer site and have implemented the following idea that works fine for two emulator instances running on same machine.
•A is you development machine
•B is your first emulator instance, running on A
•C is your second emulator instance, also running on A
and you want to run a server on B, to which C will connect, here is how you could set it up:
1.Set up the server on B, listening to 10.0.2.15:
2.On B's console, set up a redirection from A:localhost: to B:10.0.2.15:
3.On C, have the client connect to 10.0.2.2:
For example, if you wanted to run an HTTP server, you can select as 80 and as 8080:
•B listens on 10.0.2.15:80
•On B's console, issue redir add tcp:8080:80
•C connects to 10.0.2.2:8080
Now for two diffenrent machines I have to make C connect to A's ipaddress:8080. This doesn't work though. What Address should be given in place of 10.0.2.2 for this to work? The IPAddress alone is apparently not sufficient.
I've been stuck with this for abt a week. Any help would be appreciated.
Yes. It's possible. you need server between two emulator. it's not possible to connect two emulator without any intermediate. This role perform by Google App engine``.
Google App Engine is complete, scalable and affordable hosting solution. Using Google App Engine,you can do this. Check this.
App Engine With XMPP:
With the introduction of the XMPP service to App Engine, it's possible to write an App Engine app that communicates with users - or even other applications - over XMPP. XMPP is an instant-messaging protocol, used by Google Talk, Jabber, and other IM networks.
Here one good tutorial of XMPP.
One Example of App Engine..
Hope this will help you.
Update:
java.net.conectExcperion:Connection Rfused : Connect android
This exception occurs when no service listening on the port you are trying to connect.
You also need to understand Emulator Networking

CouchDB Replication to and from Android

I'm new to Android and CouchDB and have a few questions.
Is it actually possible to replicate the contents of a Windows CouchDB database to Android without developing some sort of app?
CouchApp is installed on my Motorola Defy and it says CouchDB is running on http://ip:port/.
With the build in browser I cannot verify that information, because the URL cannot be opend (neither from the phone nor from my pc), but http://localhost:port/ works fine.
I tried setting bind_address in /sdcard/Android/data/com.aranomurl.couchapp/couchdb/etc/couchdb/local.ini to 0.0.0.0 and to the actual IP, but neither one changes anything.
Using the futon replicator I get the error message "Replication failed: could not open http://ip:port/".
As a correlating question, I wonder how continous replication is supposed to work for mobile devices, since IP address and port seem to change very frequently.
(edited once to clarify that mobile futon's URL is not working)
0.0.0.0 will listen on all interfaces so it will be accessible as long as your device is, Generally on devices its a good idea to pull from the phone as opposed to push to it, then you dont need to worry about the port switching.
right now your android and windows machine cant talk to each other, this could be a variety of problems related to your local network, when you can access the url that is displayed in mobilefuton, then your replication should be fine (replicating against a public host is also an easy way to get started)
Problem solved with newer CouchDB App for Android https://market.android.com/details?id=com.daleharvey.mobilefuton
Built in [continious] replication is working fine...
As mentioned earlier, the problem is solved in the newer version of the app.
But just incase replication doesn't work,
Make sure you have the couchdb port open and accessible universally/within the network in which you want to access.
Try initiating replication from Android to Remote server always, because, as you said, Android's IP might be hard to track down and keep static!

client server android app

i have developed an android application in android sdk 2.2 . This app is having tomcat server connectivity as well as mysql database connectivity. this app is running fine on emulator.
but for deploying this app on android device do i need to configure any settting??
Not particularly, if you have it working in an emulator. But why ask this on StackOverflow? Just go out and try it on a device. Also be aware that client network connectivity is frequently slow, error-prone and sometimes nonexistent, so make sure you're handling network issues gracefully.
EDIT: The comment below would indicate this is actually a duplicate of Access dev machine localhost via usb, although the original wording is pretty unclear.

Categories

Resources