Android跨应用数据传递

发布于 2024-12-11 14:32:22 字数 314 浏览 0 评论 0原文

概述

我正在创建一个 Android 应用程序,它将扫描设备的各个方面(联系人、APNS、电子邮件等)

我希望让第 3 方应用程序能够在安装/运行/启动等时向我的应用程序注册 - 使其成为可能我的应用程序可用的数据。

问题

我如何以标准方式访问这些信息?如果我要创建一个典型的插件式桌面应用程序,我会使用某种形式的界面,但 Android 不具备这种能力。我已经研究过 ContentProviders,但第 3 方应用程序需要开发整个 SQLite 数据库以允许我的应用程序访问其数据。这似乎太过分了。

有办法实现这一点吗?

Overview

I am creating an Android application which will scan various aspects of the device (contacts, apns, emails etc)

What I would like to make possible is for 3rd party application to register with my app on install/run/boot etc - making its data available to my application.

Question

How can I access this information in a standard way? I would use some form of Interface if I was creating a typical plugin-style desktop app, but Android doesn't have this ability. I have looked into ContentProviders but the 3rd party app would need to develop a whole SQLite database to allow my app to access its data. This seems overkill.

Is there a way to achieve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

没︽人懂的悲伤 2024-12-18 14:32:22

如果我要创建一个典型的插件式桌面应用程序,我会使用某种形式的界面,但 Android 不具备这种能力。

当然可以

我研究了 ContentProviders,但第 3 方应用程序需要开发整个 SQLite 数据库以允许我的应用程序访问其数据。

不,他们没有。 ContentProvider 是一个外观。您可以随心所欲地实施一个。

我希望让第三方应用程序在安装/运行/启动等时向我的应用程序注册 - 使其数据可供我的应用程序使用。

“安装”将是不可能的。首次运行和/或启动时将是可能的。

我如何以标准方式访问此信息?

如果您的应用程序将提取数据,除了 ContentProvider 或 AIDL 接口之外,您还可以通过 startService() 向第三方应用程序发送命令,并包含一个额外的命令在 Intent 中,为第三方应用程序提供用于发送其响应的通道(例如,MessengerPendingIntent结果接收器)。

相反,如果第三方应用程序将向您推送数据,我将实现一个在清单中注册的 BroadcastReceiver,并让第三方应用程序根据需要发送广播。

I would use some form of Interface if I was creating a typical plugin-style desktop app, but Android doesn't have this ability.

Sure it does.

I have looked into ContentProviders but the 3rd party app would need to develop a whole SQLite database to allow my app to access its data.

No, they do not. ContentProvider is a facade. You can implement one however you like.

What I would like to make possible is for 3rd party application to register with my app on install/run/boot etc - making its data available to my application.

"Install" won't be possible. On first run and/or at boot time will be possible.

How can I access this information in a standard way?

If your application will be pulling the data, besides a ContentProvider or an AIDL interface, you could send a command to the third-party app via startService() and include an extra in the Intent that provides a channel for the third-party app to use to send its response (e.g., a Messenger, a PendingIntent, a ResultReceiver).

If, instead, the third-party application will be pushing data to you, I'd implement a BroadcastReceiver, registered in your manifest, and have the third party app send broadcasts as needed.

顾冷 2024-12-18 14:32:22

Richbayliss,这是一个有趣的问题。
因此,Android 在设计时就牢记这一点:应用程序之间的互操作性。因此,让我们将您的问题分为两个主要资源:

  1. 联系人、应用程序、电子邮件等
  2. 您希望别人传递给您的其他一些数据。

手机中的某些东西就像手机本身一样,就像您提到的那样。所以它的工作方式是这样的:

Android 中有多个“管理器”(例如 ClientConnectionManager),它们就像可以访问所有这些本机信息的看门人。它们无疑是访问这些资源的更简单的方法。您还可以通过沿着您提到的 sqllite 路径访问它们 - 一个例子是您可以使用游标访问从相机拍摄的照片,游标最终会查找 sqllite 数据库。

问题的第二部分 - 您想要传递的其他一些内容 - 让我给您举一个例子,说明这在 Android 中是如何工作的。您基本上必须在清单中注册某些事件 - 比如说您想知道每次有人单击“共享”时 - 您正在谈论的这些数据被捆绑并在意图中发送。您所要做的就是为此类调用注册您的应用程序,并声明一个可以处理特定类型事件的活动。简而言之,对话发生在意图之间,数据以捆绑形式传递。

Well Richbayliss, that's an interesting question you've got there.
So Android is designed keeping this exact thing in mind - interoperability between applications. So lets break up your question into two main resources:

  1. contacts, applications, emails etc
  2. some other data you'd like someone to pass to you.

There are certain things in the phone which are like native to the phone, like the ones you mentioned. So the way it works is something like this:

There are multiple "Managers" in Android (example ClientConnectionManager) which are like the gatekeepers who can access all this native information. They are certainly the easier way to access these resources. You could also access them by going down the sqllite path as you mentioned - an example for this is you could access the photos taken from the camera by using Cursors which eventually look up the sqllite db.

The second part of the question - some other stuff which you want to pass - Let me give you an example of how this works in Android. You basically have to register for certain events in your manifest - say like you want to know every time someone clicks on 'share' - this data you are talking about is bundled and sent across in the Intents. All you got to do is register your application for such calls and declare an activity which can handle a specific kind of event. In short, Talking happens between intents and data is passed in bundles.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文