I am trying to share some data between two applications with SharePreferences. (If i am goning wrong way please tell me the correct way to send data between diffrent applications). my code is like this: In Application1 (Sender):
SharedPreferences prefs = getSharedPreferences("odenevisha.com.apps.test_01",
Context.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putString("DATA", "123");
editor.apply();
In Application2 (Receiver):
try {
Context con = createPackageContext("codenevisha.com.apps.test_01", 0);//first app package name is "codenevisha.com.apps.test_01"
SharedPreferences pref = con.getSharedPreferences(
"demopref", Context.MODE_PRIVATE);
String your_data = pref.getString("DATA", "No Value");
Log.e("LOGO", "TEXT IS: " + your_data);
}
catch (PackageManager.NameNotFoundException e) {
Log.e("LOGO", e.toString());
}
and in the manifest of both Applications, I defined this below line into Tag:
android:sharedUserId="any string"
android:sharedUserLabel="@string/label"
but it does not work! what is the problem?