在Android的两个应用之间的数据共享 [英] Data sharing between two application in android
问题描述
我有两个应用程序。
一为主要应用..另外一个标题换..
One for main application.. another one for title changer..
如果我输入标题在一个应用程序它在另一个应用程序的影响。
If I enter the title in one application it affected in another application..
什么,我试过了,的
What I am tried,
我已经被存储在数据库做SD使用card..And参考DBHelper称号。
I already done by store database in SD card..And refer title using DBHelper.
我的问题,的
My problem,
但现在我的数据库移动到主应用程序..所以我无法从标题换应用参考数据库。
But now my database moved into main application.. so I cannot refer database from title changer application.
我的问题,的
My question,
如果没有数据库创建我能传递两个application..like意图或共享preferences之间的数据?
请注意:这两个应用程序存储在同一个设备。
Note: both application stored in same device..
推荐答案
从应用程序发送1的数据(例如:申请1包的名称是com.shared preF1)。
SharedPreferences prefs = getSharedPreferences("demopref",
Context.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putString("demostring", strShareValue);
editor.commit();
在收到申请2(以获得从应用1共享preferences数据)的数据。
try {
con = createPackageContext("com.sharedpref1", 0);//first app package name is "com.sharedpref1"
SharedPreferences pref = con.getSharedPreferences(
"demopref", Context.MODE_PRIVATE);
String your_data = pref.getString("demostring", "No Value");
}
catch (NameNotFoundException e) {
Log.e("Not data shared", e.toString());
}
在这两个应用程序清单文件添加相同的共享用户ID和放大器;标签,
android:sharedUserId="any string"
android:sharedUserLabel="@string/any_string"
都是一样的... ...和共享用户标签必须从string.xml
both are same... and shared user label must from string.xml
这样的例子。
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.xxxx"
android:versionCode="1"
android:versionName="1.0"
android:sharedUserId="any string"
android:sharedUserLabel="@string/any_string">
这篇关于在Android的两个应用之间的数据共享的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!