How to "send" a variable from app to a different module? - java

I had an original stand alone java code, that could be used by multiple computers in order to find the answer in a distributed systems fashion. Alternatively, I could run everything I needed in eclipse by running a few projects at the same time, instead of one component in each computer.
Now I want to extend this project in Android Studio. The basic idea is that the user gives some input in the app and then ,after some processing, some output comes back.
I have tried using modules (since I cannot separate the different components with projects) and I have not been able to replicate my result.
My questions are :
Can different modules in Android Studio be run simultaneously, like
different projects in eclipse ? If not how can I find a solution ?
If yes, how can I make the modules and the app communicate between each other? e.g. I have an EditText, which I save it as a String variable. How can I send it to a different module for it to be processed or passed on to different modules ?

To the discussion in the comments seems you want to pass data from your computer (or a computer that I'll call server from now) to your Android app (that from now I'll call client).
What you are trying to achieve so is the client-server architecture (standard use):
client make a request of some data of the server
server sends data to client
client process data or show data to user
The decision about how the communication should be it's up to you. There are many possibilities (web-socket, custom API REST), but it's up to you and your capabilities.
Is it really hard to explain in just one answer the whole process from the code view, so I link here for the client part.
Also, this question could really help you.

Related

How can I implement remote server which will run on separate process in android?

I need to create two different applications (two different processes) in Android. One will have activity and the other should just be service which would be started from the activity code.
I need it to be separate because in service I need to create one more instance of SDK that I am using in my activity.
I can't find any example how to implement and connect these two applications, does anyone can help me?
Thanks in advance
I'd suggest not doing it at all. Android is really not set up to be a server, with power limitations and the ability of the OS to kill background processes at any time it just isn't meant to be reliable- which is exactly what a server needs. I would suggest reposting with more details of what you need (because "need to create one more instance of SDK" doesn't make any sense- SDKs don't have instances, and why would you not be able to do more than 1 instance in your Activity) and seeing if you can get alternative architetures.

Getting user behavior on the Android Phone (App History, Browse History etc)

Is it possible to get the user behavior on the phone (for example Alpesh has an Android phone and he uses multiple apps, browser YouTube etc). Whatever he is doing on the phone I want to get all those things from behind (which apps he has installed, which app he opens and what he search on the phone, All these data I want to get programmatically so what all can be get in android).
For now I am aware that installed apps list can be get easily but I want to get usage history and what he do all on mobile.
This is not a code solution, but an answer to your question, so you can get start some where.
In my opinion your question title are asking about two things.
(part 1) Getting User Behavior on the Android Phone (part 2)(App History, Browse
History etc)
1- First part Getting User Behavior on the Android Phone:
There is a concept called context awareness. Short described; it is about gathering different information from the phone, like light sensor, motion sensor, sound, location or even user behavior etc. and depending on your app requirement and the gathered information:
You could send these information over cloud data store for statically usage
You could make your phone doing (behavior) different things depending on location, motion or what ever.
etc.
For context awareness it is an open area for pervasive computing research. And it is not just few lines of code to write, it is typically a complete solution depending on requirement. Example I have built a context awareness application to gather noise collected by phones from different locations for research purpose inspired from this framework, but I am pretty sure you can find other frameworks or even build your own, as I did in my case.
The mentioned framework has some examples.
2- The second part is about App History, Browse History etc.:
This is possible, but you still need to build a peace of software (App) to collect all these information (logs) from the phone. Hereafter you can make phone act on different conditions and/or again send it over a RESTful API over cloud service data store, there is no limit for it.
The problem is, there is no thing out of the box for your requirement. Even if you find frameworks you still need to research it and further work on it.
You can find different examples for your requirement, like to collect browser history, you can find SO question here:
Get browser history and search result in android
Or get list of installed application:
How to get a list of installed android applications and pick one to run
My point here is you need to solve small goals at a time and put your knowledge together at the end.
Both 1 and 2 can also be related to each other, depending on your achievement.
Conclusion
Make a goal to your project.
Define the main requirements and tasks of your project.
Research your options (Technology, Cost, Target Audience, What data I can or I should not collect, what is possible to collect, what is the limits, Privacy issues etc.).
Split your project in small assets and try to solve small problems/goals.
Finally you would be able to put the puzzles together and build your final application
but i want to get usage history and what he do all on mobile
This is not possible and shouldn't ever be possible. Each app is sandboxed by Android so apps cannot inspect what other apps are doing. Think about it, you wouldn't want apps to be able to intercept private information such as banking details.
Every app is isolated from the other ones. Unless you develop a system signed app, you will not be able to gather all that data.
What you could do is to develop your own Android Rom where you then develop your data collection the exact way you want. Then you need to distribute your rom, which is another story...

how to send post data continuosly to web and mobile

I am going to develop uber-like application.Here I have to send latitude and longitude to web and mobile devices continuously with my service,What I have do to get this.
Can anyone please give some idea.
You should start by designing how the application is to be used, seen from all the different users perspectives.
For instance is this a web app, or a native app, or both?
Then from that knowledge, you need to define a communication protocol.
You should be able to determine if the client will be polling for data, or if you need to push it from the server onto the clients.
This also goes for the data that travels the other way.
From here you choose a language for programming, and then start doing some proof of concept tests.
The choice will depend on the chosen underlying technologies
(web / native / os / available libraries)
After some test work you may have something that works, then you need to review or add security to the communication, cause we do not want everyone collecting location data from everyone that has the app installed.
Then run beta trials and eliminate the worst bugs, and then release the app.
You'll want some sort of asynchronous task which can get new data from your server and refresh the mobile and web content to reflect the content of the server. You'll also want to notify the server whenever you make local changes to content and want to reflect those changes. Android provides the SyncAdapter pattern as a way to easily solve this pattern. You'll need to register user accounts, and then Android will perform lots of magic for you, and allow you to automatically sync. Here's a good tutorial: http://www.c99.org/2010/01/23/writing-an-android-sync-provider-part-1/

How do I connect my Desktop Java Application to an Existing GAE Datastore?

Currently I have a very basic desktop Java application in Eclipse that is meant to add entities to an existing project's datastore on Google App Engine. I have it all setup right now but since I am new to working with Google App Engine, I have no clue on how to get the application to send the Entities into the datastore of my existing project.
I tried looking this up online but most of what I found was for making java web apps. My goal is to have the application running as its own application, not through a browser.
So, what do I have to do to make the application connect to my GAE datastore? Is there some code I need to type, or perhaps some xml file I need to have within the project? I am just using the Java Eclipse plugin for Google App Engine.
Thanks for the help!
Based on the language of your question, I think you really need a big-picture sort of answer, rather than any specific code. Therefore:
You have a desktop application. This runs on some desktop computer.
You have a Google App Engine application with its data store. This runs in Google's data centers.
These are not the same computer. Therefore, they must communicate over the network in some fashion — that is the missing piece you're looking for.
Since GAE is designed around doing web applications, I recommend you think of this as a “web service” situation — that is, your desktop application makes HTTP requests to your GAE application. (The situation is simplified over the general case because you are writing both the client and the server.)
I recommend you read about designing simple web services and do whatever seems to fit your application.
One important warning: Unless your GAE application only ever has one user, you must not simply write a bridge that gives access to the data store over HTTP, because then anyone can make arbitrary changes to other people's data. As it is said for multiplayer game design: don't trust the client — that is, only accept network requests that make sense according to the rules of your application, and do not expect the client to enforce those rules. This is because anyone can make requests to your GAE application using something other than your desktop application, so you must assume you could receive arbitrary requests. This is the fundamental nature of the Internet.
For example, in the simple case of a multi-user application whose users do not interact with each other using the application, this means that every request that, say, updates a record, should only update a record which belongs to the logged-in user, not one of any other user.
For anyone that gets this problem in the future, I got an answer to it. I just tried experimenting around with the project settings and found it. So as it turns out, after you have installed the GAE Eclipse Plugin, you can just right click your project folder in the Package Explorer, go the Google sub menu, then click on App Engine Settings... .
From there, you need to check the Use Google App Engine checkbox, then in the deployment section, just fill in your project's Application ID. Your project's application ID can be found under the Application Settings tab of your project's online Google app engine dashboard. It is listed there as your Application Identifier.
Turns out that for me, I will need to find a different solution as you cannot integrate GAE with a desktop application that uses the Java Swing library. Bummer :/

Connect multiple desktop apps to one online database

I'm starting a new project. It consists of:
Java desktop application downloadable from the internet with a client database.
PHP website on the internet with a server database.
The user who downloaded the app will use it to add items (not important what are they now) to the local database offline. When/If he is online, the item will be added to the server database so other connected users (through the desktop app or through the website) will see it.
I googled the issue and found it's more complected than I guess. One of the solution is to use some ready tools like SymmetricDS and Daffodil to gain in term of security, performance and scalability, but they're difficult to configure and install in both client and server side, and need the access to command prompt which requires me to pass to a dedicated host (well, that is not a real problem). Also, all what I want is just what I've described, not all what these tools actually provide.
Can I achieve that by myself within my Java application and maybe with the help of
the web server PHP?
I'm using MySQL for the info.
Edit: what really matters is to send items to the server database. Reading it can be less tricky using RSS Feed reading, for example.
Basically, you can use HTTP/HTTPS API. When a user online, send items to your php file and mark the items "sended" at local database. But you have to control edited or deleted statuses. So, yes that is much complicated but a solution.
Well the easiest solution that comes to my mind would be to save for each item a last edit date (on the server as well as on the client). Additionaly you have to keep track when a client got his last update from the server.
So whenever a client goes online the server sends him all updates.
But for that you have to make sure that the time on the client and the server are the same, and it doesn't solve the problem what happens if two clients edit the same item.
CouchDB solves the distributed synchronization problem very nicely, but it is a NoSQL DB. Depending on what your application should do, using it would boil down to using instances of CouchDB both locally inside very application, and on the central server.
You'd have to deal with conflicts nevertheless. The only thing CouchDB will support you with is easier detection of conflicts, and the data of both conflicting edits, so your application can work it out either automatically, or with user help.
On the other hand, generatin a unique id on the central server can be as easy as adding the creating user's id to each item id.

Categories

Resources