Sharing String between two applications - android

I have two applications and I want to be able to share a String value between them. For example: user changes the String in app A, when app B is launched, I want it to read the updated String (and vice versa).
I was trying to use SharedPreferences with Context.MODE_WORLD_WRITABLE, but it's been deprecated.
How can I achieve this?
EDIT: App A has to save the value without launching app B. App B has to be able to read that value without launching app A.
I looked at ContentProviders, but they look too complex, especially for a simple String sharing.

One option is use webserver for this. for example store value in web server from app1 and access this value from app2
option two is use content providers. Through the content provider, other apps can query or even modify the data (if the content provider allows it)

Simply put:
one application needs to send intent with data
the other one needs to listen for it with brodcast receiver.
Content provider is probably not the thing you are looking for.
here is good tutorial for brodcast receiver

Try http://developer.android.com/training/sharing/send.html or http://developer.android.com/guide/topics/providers/content-providers.html to share data between 2 applications

Related

How to create option for your app in another app in android

whenever my app will run, it will create one option in another app to get data from another app.
Well, I am not sure this is possible or not, Please guide
one more I know how to share data in between two app by using sent action but I want to create one separate option in another app for my app when my app start running in android
Is it possible ?
Please guide , Thanks in advance
A content provider component supplies data from one application to others on request. Such requests are handled by the methods of the ContentResolver class. A content provider can use different ways to store its data and the data can be stored in a database, in files, or even over a network.
Link1
Link2
You can do this thing this way :
Intent i=new Intent();
i.setPackage(TARGET_APP's package name);
context.startActivity(i);
You can set value this way with this intent
i.putExtra("KEy",value)
http://developer.android.com/reference/android/content/Intent.html#putExtra%28java.lang.String,%20double[]%29
On the other hand, if you want to read some data from an app, it's possible if and only if that app allows you to do so. Data generated by the app is private by default.
Another way to do this by using content provider
May be this link will help you more about content provider
http://www.tutorialspoint.com/android/android_content_providers.htm

Changing one apps preferences from another app

I have two apps and I want one app to change preferences in another app.
Is it possible? If so, then how?
It means that you need some passage between two applications.
If A application provides content provider, B application can access that content provider and change values in that provider.
Have a look this article http://developer.android.com/guide/topics/providers/content-providers.html
You could use Content Providers. Put your settings in a database so that the other application can read.

Sending parameters from one apk to other

I am able to launch an apk from the button click of other apk. but i have to send parameters also.Like if i am giving values in a text and when i click the button then it should send the parameters to other apk as well it should start other apk. I know how to send parameters between activities in the same package. Please guide me how do i do it.
Update:
I have successfully run that apk's. I just had to put package name instead of class name.
Use
i.putExtra(param, value);//Put extra values to your intents, if you are using intents to launch another app.
You need to use content providers to share data across different applications in Android. Here
is an example as to how to use them. You need to have a URI which identifies your dataset and use the same URI in another application to retrieve data from it.
Use Intents, as explained in Android Developer Documentation or many tutorials over the internet.
You should use Bundles to pass parameters, as you can read there.
You can use files in a common directory to comminucate different apps or basicly you can have serversocket in your first app that runs the other one, so the second one can connect it and transfer data to/from first app.

The easiest way to pass data between application in Android

What's the easiest way to pass data(string value) between two android applications with less or even without permissions? Also in my case first application sends data to un-existed application which is installing and it can't listen for intent right now.
Thanks.
Your question is tricky when you can't ensure that both applications are running. In cases like that, you must rely on some form of persistent storage.
If you're concerned with only a small amount of data, Android provides a SharedPreferences class to share preferences between applications. Most notably, you can add a OnSharedPreferenceChangeListener to each application so they can be notified when the other changes the value.
You can find more information on various different forms of persistent storage on the Android website (http://developer.android.com/guide/topics/data/data-storage.html).
So as you are mentioning intent and extras put to it is the way to go.
If you want to let an application receive data even if it's still installing there is no straight-forward way.
One way is as follows:
In the receiver-part of your code, send a received successfully-extra to the sender-application. If the sender-application does not get the received successfully-message after some time, store the data and wait until the application is installed. you may store this data on sd-card and let the other application read that on first use.
you can also do a check if the application is installed with PackageManager.

android contentprovider

I’m a beginner to Android development. Something always confuses me. Let say if I want to create a simple app that shows all presidents of United States with some brief info, how do I store this information? Should I store these information in content provider while activity oncreate? Doesn’t it append the data everytime when user start this activity?
Should I store these information in content provider while activity oncreate?
You never store data in a content provider... a content provider is used in order to (guess what?), provide content. In most cases you won't need to create your own content provider; unless you want to share that data with other apps. If the information you are going to handle is going to be used by your app only, don't create content providers... just put your data in a database and access it from there.

Categories

Resources