How to call a java REST web service from android phone - java

I have built the client using Android and the server using java REST web services.I am able to access the server while running the android code on emulator.However,when I install the .apk file on my mobile and try calling the
REST web service;it does not connect.No communication between the two is initiated.

Check if you are using your public IP address to connect to your server(from client) or not. The URL that you provide in your client should have public IP and not private one.
To determine public/private IPs, please go through the below link
http://www.howtogeek.com/117371/how-to-find-your-computers-private-public-ip-addresses/

Related

connect and communicate between Windows application (c#) and andriod apllication (java)

I am trying to connect and communicate between Windows application and andriod apllication. I have used .Net Socket but it is only appllicable for windows. how can i code in andriod application using Java programming language and make communication between two seperate devices (windows and andriod).
I want windows application act as a client and andriod apllication as a server. The server receives the data from client, processes the data and returns the result to the client.
Thank you all in advance
There are several ways to connect and communicate between a Windows application (developed in C#) and an Android application (developed in Java). Here are a few options:
1/ Use a web service: One option is to create a web service that both the Windows and Android applications can access. The web service can be hosted on a server and both the Windows and Android applications can send HTTP requests to the web service to retrieve or send data. This is a good option if the applications need to communicate with each other over the internet.
2/ Use a local network connection: If both the Windows and Android applications are on the same local network, you can use a local network connection to communicate between the two. For example, you can use sockets to create a connection between the two applications and send data back and forth.
3/ Use a shared database: Another option is to use a database that both the Windows and Android applications can access. You can set up a database server and have both applications connect to it to retrieve and store data. This is a good option if you need to store large amounts of data and need the data to be persistent.
4/ Use a cloud service: There are also several cloud services that allow you to easily connect and communicate between Windows and Android applications. For example, Google's Firebase provides a real-time database that can be accessed by both Windows and Android applications, as well as other features such as push notifications and authentication.
It's worth noting that each of these options has its own set of pros and cons, and you'll need to choose the one that best fits your needs.

which IP address should I make in the Post method?

I made an API between an android application and a desktop application (java). I test that in local between android studio device and my desktop application and it works with local address:
post("http://10.0.2.2:8080/api/v1/locations", json)
but now I want to install the app in my phone so I'm not in local anymore, I want to know which address should I make to post from my phone to my laptop java application?
You need to deploy your service that you have created on some server then you can access same.
so the IP you need to use of server.

Integrate a finished web service in a Android application

I don't know if the correct term is "integrate" or "connect" a finished web service in a android application. I mean,
Is there any possibility to "integrate" a finished RESTful Web Service in a Android application, which I have not developed, yet.?
Otherwise,
Are there some steps to develop a RESTful web service which I need to use from a Android application?
The last question is asked because I don't know if the first step is to finish my RESTful Web Service and then integrate it in my android application or or developing the RESTful web service and the android application at the same time.
In any case, how I can do it well? I need help to organise my mind
You will need three things:
Client(your app)
Server
Database
Lets say you have to create a login service for your app. Then your steps should be like given below:
Create a login form with android UI.
Get username and password from Edit Texts in strings.
Send these credentials to server(via http reqest).
At client side read response from url via input stream.
At the server side, use a server side technology in which you are familiar with.(If you are not familiar with any server side tech. I strongly recommend you php.)
Select/update/compare (Whatever you want) in data base and return response as a json string.
You can use server on your system. I suggest to use XAMPP(cross platform apache mysql php perl). As its name says, it includes server+database+php (its local). It will create a local apache server on your machine.
Follow this : XAMPP Tutorial , Working with XAMPP
Here are some nice tutorials of web services with android:
How to connect Android with PHP, MySQL
Using Database from an Android Application

Android apps calling web service design logic

I has an android apps install in my galaxy tab. This apps will call a web service in the web server which locate in the office. The web service then will call to database in another server. The web server and database server is in same LAN. My web server IP is dynamic which will change every time the modem is restarted and I do not register any domain name. How I can configure my router/modem to let the apps can call the web services which the ip is not statics? Is it possible? Please help.
What is OS of your webserver running ? Windows or Linux? You should configure a static IP for your webserver machine. This way webserver IP 'll not change after modem is restarted. You may find this in Google search

Sync desktop application with android application

I want to raise an event from my Android application to my desktop application which is in Java. Can I do so? If yes, which API to use? Any examples or code snippets?
Both android and desktop applications are clients. Two clients can talk to each other via server or at least initialize their connection via server that is running on pre-defined location (IP address). So, you need some server that allows to do this.
You can probably use (or abuse) some 3rd party servers for this. For example if your desktop application "knows" the phone number it can send SMS via one of available web services. The android application will catch the SMS and take information from its text. You probably can use Skype installed on your machine or email to send messages among applications too. But better way is to develop your own server that exposes RESTful API and use it for the negotiation.

Categories