Rof*_*ion 28
ContentProviders是在应用程序之间共享数据的好方法.
Ran*_*mar 28
从Application 1发送数据(例如:Application 1包名称为"com.sharedpref1").
SharedPreferences prefs = getSharedPreferences("demopref",
Context.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putString("demostring", strShareValue);
editor.commit();
Run Code Online (Sandbox Code Playgroud)
接收应用程序2中的数据(从应用程序1中的共享首选项获取数据).
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());
}
Run Code Online (Sandbox Code Playgroud)
在两个应用程序清单文件中添加相同的共享用户ID和标签,
android:sharedUserId="any string"
android:sharedUserLabel="@string/any_string"
Run Code Online (Sandbox Code Playgroud)
两者都相同......共享用户标签必须来自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">
Run Code Online (Sandbox Code Playgroud)
我怀疑他们可能正在寻找 Android 特定的方法,例如内容提供商的答案。
其他替代方案... Android 特定 - 远程服务 常规 - TCP/IP 连接 常规 - 写入 SD 卡上的某个位置
想了解更多有关特定方法的信息吗?
今天也偷了这个问题来接受采访:)
小智 5
如果要在应用程序之间共享数据,请确保使用相同的密钥签名:
通过权限共享代码/数据– Android系统提供了基于签名的权限实施,因此应用程序可以向使用指定证书签名的另一个应用程序公开功能。通过使用相同的证书对多个应用程序签名并使用基于签名的权限检查,您的应用程序可以安全方式共享代码和数据。
如果数据量很少,则可以通过意图将其发送。
| 归档时间: |
|
| 查看次数: |
51574 次 |
| 最近记录: |