I have been doing research on how can i share data between two applications. Here is what am trying to accomplish. I have an ocr application and an XMPP application. XMPP application has been connected to openfire server and is successfully sending messages from android mobile phone to spark client messenger on my laptop. Now what i want to do is take picture through camera in the ocr application and then convert it to text which is being stored in a string. Now i want to provide that string to XMPP client application on my mobile phone so that it can send that text to the spark client messenger on my laptop. I have am successfully able to explain my scenario here. i tried socket programming to do this but failed. Then i saw somebody saying that it is possible to do this through sharedpreferances object but it does not make sense how would the xmpp application know that ok now the ocr application has converted the text and i should receive it. Please Help me solve this problem. Explanation along with some code would be highly appreciated!
2 Answers
Use Broadcast Recievers(http://developer.android.com/reference/android/content/BroadcastReceiver.html) for sending data across applications.
This might help How to use Broadcast Receiver in different Applications in Android?
Your questions is : How to send data from ocr application running your phone to xmpp application running in your same phone.
Basically you are looking out for a solution on how two apps (processes) will communicate.
solution:
Pre requisites1 : have an ACTION agreed for both ocr and xmpp applications to be broadcasted.
Pre requisites2 : Create a database table in your ocr app to store your text.
Pre requisites3 : create a content provider on top of your database
Now, once in your ocr application you take some picture, Put that camera converted text data into your database table. Send a broadcast with above agreed ACTION so that XMPP app will understand that your data is ready. While sending this broadcast send the URI for the table in which you have put text to be shared.
On the other side, once xmpp app receives the broadcast in its receiver, based on URI, it can query and fetch the data from the table of ocr app through content resolver.
Note: You can directly store your camera picture in sd card, and can put the path of that picture in your database table. Rather than converting picture into text format.
This is just my random thought on how you can do it. Probably you can get better technique than this.
Other ideas that you can look into are:
Put a common shared memory, between two applications. put shared data in that memory area and access it. (like how binders will internally work)
Give same user id for both ocr and xmpp application so that xmpp can directly access the data of database tables of your ocr app. If two apps are having same linux user ids then both can share the shared preference files or database files.
Hope it helps.

- 4,684
- 35
- 29