Interaction between Java and Android - java

I am currently trying to research how to use Android with an existing java based system. Basically, I need to communicate to/from an Android application.
The system currently passes object data from computer to computer using ActiveMQ as the JMS provider. On one of the computers is a display which shows object data to the user.
What we want to do now is use a phone (running Android) as another option to show this object data to a user with wifi/network access.
Ideally we would like to have a native application on the Android that would listen to the ActiveMQ topic and publish to another Topic and read/write/display the object data, but from some research I have done, I am not sure if this is possible.
What are some other ways to approach this problem? The android Phone needs to be able to send/receive data. I have been using the AndroidEmulator for testing.

A quick and dirty way would be to have your JMS pushes the data to a XMPP/Jabber server and use a XMPP library like Smack API on the Android to connect. The advantage of this approach is that
You can emulate the point-to-point and pub/sub in JMS.
XMPP is quite extensible so what you can do is instead of carrying your payload as 'chat' text, you can create your own namespace within the XMPP packet. For data portability, you can use a lightweight like JSON in the namespace.
XMPP will handle your presence for you so your app don't have to keep track of services if they are online.
There is a nice article here that shows you how to use Smack on Android.

Related

Consuming MassTransit+RabbitMQ messages in non .Net applications

I plan to implement the message bus where messages would be produced in .Net Core application but consumer applications are to be running on Android devices and written on Java. In initial approximation publisher application will know nothing about consumers. Java tablets will subscribe to message bus, receive messages and unsubscribe from bus. It looks like I'll need to dynamically create queue for each of the Android tablets, bind it to fanout exchange and send messages to the exchange or something like that. For .Net there is the MassTransit framework that already have all this stuff but I am not aware of Java and Android Studio capabilities. I am curious is there any way or a workaround to implement MassTransit consumer application on Java? I've been googling about 2 hours and didn't find any info but I assume that my search requests were incorrect.
MassTransit uses JSON by default for messages, the structure of which is documented on the web site. You can also send raw JSON messages if the envelope structure used by default is unnecessary.
As for how to consumer RabbitMQ messages from an Android device, I don't have any input there. Surely there is a client SDK.

Spring webapp: sending notifications to java and android clients

I recently started developing my first web application with Spring and I'm stuck with a question I could not really find an answer to. What I have is a simple Spring MVC application running in tomcat which provides data in form of JSON, XML or binary via REST. This service is consumed by two clients I developed, a simple Java desktop application and an Android app. So far the clients only got information about new data by polling.
What I want now, is a way for the server to send notifications/messages to the clients when new data is available. For the Android client it would be good if the notifications could received anytime, not only when the app is currently open of course. I found lots of information for JavaScript client code but very little really useful, up-to date input about what the options for java and android clients are.
It would be really great if someone could give me some idea what would be the best way to achieve what I want (ideally something which integrates well with Spring on the server side), what protocols/libraries/frameworks to use, maybe even point me to some example or tutorial, how to implement this on server and client side.
Thanks in advance for any input.
For android or mobile devices, Google Cloud Messaging is the preferred way of sending messages to applications running on devices.
Example : spring gcm server side project and a sample tutorial.
For desktop apps, either poll regularly the server or run something in background like crontab or active-mq to check the messages and start the desktop app.
WebSockets are the best solution. check the implementation in java in the server side

Web server/db online to communicate with android?

I'm new in android and i want to know if there is some server / web service online that o can use to update and communicate with my app?
example: I have the app "message" in 5 phones so I want to communicate with all of them, if the phone 1 send a message all device must receive notification.
There is something that I can use maybe free?
You have many options to accomplish this goal, and most provide some free level of support.
In general if you want to "push" notifications to android devices, you can either directly use or use some provider that uses Google Cloud Messaging.
Using this approach directly means you need some web server to send request to, which will then forward a request to Google, which will then forward your "message" to the devices you want to reach. There are many options for free hosting of (smallish) web services. IBM's BlueMix and Heroku come to mind. So if your are comfortable writing web apps, this might be a good choice. I have used both (for Ruby on Rails backends to mobile apps) and found both very good, but am currently using Bluemix.
I believe Bluemix along with Parse also offer mobile data storage and easy access to Push notifications to both Android and iOS. I am currently using Bluemix via Ruby on Rails and pushing messages directly to devices via GCM and don't have much experience with those particular offerings.

Android Client-Server App & Web Services

I have a website that I'm wanting to create a Java application for, and while I don't have any experience creating android applications I have a decent amount of Java experience and feel like I should be able to complete this task over some time. I'll be making use of the Java.IO package for client-side networking (On the application) and hosting a server using Java. This server application will have access to all of the same databases as the website through JDBC. (I'll be hosting it all on the same server.)
My question is how to go about handling connections on the android platform, currently I verify a dynamically generated salt with the database salt on every page refresh to prevent session theft. I also make sure that the encrypted password and the user-name stored in the session match.
I could theoretically just create a standard server application, using NIO and avoding the whole thread-per-client scenario. The problem is that my website has quite a bit of traffic, and I know the application will too. So I'm running into issues on how to handle it.
If I use a keep-alive TCP connection and store the users basic information in a class data structure (Psuedo example):
class User {
int id;
}
Considering all information will be polled from a database and everything is relative to the id of an account, there's no reason to store any excess data into the User class, correct? Just a quick simple lookup tied to the connection to only get data relavent to yourself.
Should I avoid the use of TCP networking for this? What do you guys think.
On the server side, create REST web services that invoke CRUD operations on the server database, and return the responses to the client as a JSONObject or JSONArray. Android has internal support for JSON parsing, and you can use the Volley library to call the web services. Volley is a pretty abstract, high-level HTTP library that makes it very easy to make REST web service calls. TCP connections are quite low-level and are not generally used in client-server Android apps. See the Transmitting Network Data tutorial for more on this.

How to securely establish communication between two apps built on google app engine?

We have come across two apps made on google app engine (java) and we need to establish a secure communication between then. Basically we have:
APP1: "Public" APP that provides data in JSON format based on requests in JSON format. The data is private, subject just to the specific request.
APP2: "Internal/Not public" APP that request data to APP1 in JSON format and needs to receive response in JSON format.
The scenario above is working fine, we have both apps communicating between each other. However, we need this communication to be secure and we need to identify (authorization and authentication process) that is really the APP2 that is requesting data to the APP1.
We have thought of many approaches but we haven't come across a final solution, I was hoping someone has implemented something similar.
1) We thought about using oAuth, building a "Provider APP" and making APP2 subscribing to our APP1 through this provider. The reason for us to have look at this solution, it's that maybe in future we will allow a third party app (APP3) to consume the data from APP1 in a subscription mode.
Regards.
Requests from one app to another will always have the X-AppEngine-Inbound-AppId header set to the AppID of the originating app. This header can't be forged by other apps or external services - it's sanitized by the App Engine system.
As an editorial note, though, it's rarely a good idea to separate your app into two separate apps like this unless you really do have an API that could be used equally well by external services. Organizing your app's responsibilities internally is generally much more efficient and just as effective at separating concerns.
This functionality is now built into the App Engine API. Apps can securely assert their identity to other apps.
ref:
http://code.google.com/appengine/docs/java/appidentity/overview.html#Asserting_Identity_to_Other_Systems

Categories

Resources