在 2 个 Android 应用程序之间共享数据 [英] Sharing data between 2 Android applications

查看:64
本文介绍了在 2 个 Android 应用程序之间共享数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经历过很多类似的回答,但是因为最近很多事情发生了变化,所以我想再问一次.

I have gone through a lot of similar answers, but since a lot of things have changed recently, I wanted to ask it again.

我有一个应用程序 A,它在共享首选项中存储数据.我希望应用程序 B 能够访问应用程序 A 存储在共享首选项中的数据.

I have an application A that stores data in Shared Preferences. I want application B to be able to access the data stored in the Shared Preferences by application A.

到目前为止的发现 -

  • 我们不能将 WORLD_READABLE 用于共享首选项,因为它具有已弃用.
  • 我们不能使用 sharedUserId 来共享数据,因为它已经被已弃用.
  • 我还了解到使用相同密钥签名的应用可以访问每个别人的代码和数据.但是我们可以通过这样做来访问数据吗?(或者我们是否还需要在签名的同时做其他事情?过程?).如果是,如何?
  • We can't use WORLD_READABLE for Shared Preferences, since it has been deprecated.
  • We can't use sharedUserId to share data since it has been deprecated.
  • I also read that apps signed with the same key can access each other's code and data. But can we access the data just by doing that? (Or do we need to do something else also along with the signing process?). If yes, how?

其中一种解决方案是使用内容提供者(数据源是共享首选项)共享数据.还有其他方式可以共享数据吗?

One of the solutions is to share the data using Content Providers (data source being the Shared Preferences). Are there any other ways to share the data as well?

推荐答案

我还了解到使用相同密钥签名的应用可以访问彼此的代码和数据

I also read that apps signed with the same key can access each other's code and data

仅通过 sharedUserId.

还有其他方法可以共享数据吗?

Are there any other ways to share the data as well?

你可以:

  • 让一个应用公开另一个应用启动的服务并通过Intent extras 传递数据
  • 让一个应用公开另一个应用绑定的服务并通过 AIDL 参数传递数据
  • 让一个应用向另一个应用发送一个明确的广播Intent,数据包含在Intent extras
  • 让一个应用程序在另一个应用程序中启动 Activity,其中数据包含在 Intent extras
  • Have one app expose a service that the other app starts and passes the data via Intent extras
  • Have one app expose a service that the other app binds to and passes the data via AIDL parameters
  • Have one app send an explicit broadcast Intent to the other app with the data included in Intent extras
  • Have one app start an activity in the other app with the data included in Intent extras

这些选项与 ContentProvider 解决方案一样,可以通过 Android 的权限系统来保护.如果你仔细设置了自定义权限,protectionLevelsignature,这些应用之间将能够相互通信,但其他应用将无法侵入那些沟通渠道.

Those options, as with the ContentProvider solution, can be secured by Android's permission system. If you carefully set up a custom permission, with a protectionLevel of signature, those apps will be able to communicate with each other, but other apps will not be able to hack into those communication channels.

当然,另一种选择是只拥有一个应用程序.

And, of course, another option is to just have one app.

这篇关于在 2 个 Android 应用程序之间共享数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆