用于加密存储的自定义 ContentProvider

发布于 2024-10-08 11:13:21 字数 186 浏览 0 评论 0原文

我有一些加密存储(SQLite)并且想实现我自己的ContentProvider。前提条件是:

  • 只有在以下情况下才应授予/可能访问 权限: 工作/开始我的应用程序 - 总而言之 其他情况必须拒绝访问 返回给用户/应用程序一些 智能消息/返回码

所以问题是:这可能吗?如果是,请给我一些如何开始的提示。

I have some encrypted storage (SQLite) and would like to implement my own ContentProvider. Precondition is:

  • Access should be granted/possible only when
    works/started my application - in all
    other cases access has to be denied
    returning to user/application some
    intelligent message/return code

So the question is: is it possible? If yes, please give me some hints how to start.

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

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

发布评论

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

评论(3

乜一 2024-10-15 11:13:21

ContentProvider 无法直接显示错误消息,但它可以抛出 RuntimeException,并且您可以将所需的任何消息写入 RuntimeException。 RuntimeException 将被打包并发送给调用者,无论调用者是谁,都由他们来处理代码中的异常。

我不是 100% 清楚你所说的“仅当工作/启动我的应用程序时”是什么意思。不幸的是,ContentProvider 没有一种与外界通信的简单方法:您无法绑定到服务、发送意图、获取应用程序对象等。如果您的 ContentProvider 在与以下相同的进程(因此相同的 DalvikVM)中运行如果您的应用程序可以通过公共静态字段和方法相互通信,例如:

public class MyApp extends Activity {
    /** True when my app is running, can be accessed by anyone in this process */
    public static boolean myAppIsRunning = false;
}

请参阅 http://developer.android.com/guide/topics/manifest/provider-element.html#proc 了解有关控制 ContentProvider 进程的信息。

祝你好运。

A ContentProvider cannot directly display an error message, it can however throw a RuntimeException and you write whatever message you want into the RuntimeException. The RuntimeException will be parceled up and sent to the caller, whoever that may be, it is up to them to handle the exception in their code.

I'm not 100% clear on what you mean by "only when works/started my application". Unfortunately ContentProvider doesn't have an easy way to communicate with the outside world: you can't bind to a service, send intents, get the Application object, etc. If your ContentProvider runs in the same process (and hence same DalvikVM) as your application then they may be able to communicate with each other through public static fields and methods, for example:

public class MyApp extends Activity {
    /** True when my app is running, can be accessed by anyone in this process */
    public static boolean myAppIsRunning = false;
}

See http://developer.android.com/guide/topics/manifest/provider-element.html#proc for info on controlling ContentProvider process.

Good Luck.

帅的被狗咬 2024-10-15 11:13:21

我不确定我是否完全理解您的问题,因此这个答案可能不适合您。

如果您希望用户能够选择哪些应用程序可以访问数据,请查看定义您自己的权限,其他应用程序可以像任何其他 Android 权限一样请求这些权限。

http://developer.android.com/guide/topics/manifest/permission -element.html

I'm not sure I understand your question fully so this answer may not work for you.

If you want the user to be able to select which applications can access the data, have a look at defining your own permissions that other applications can request just like any other Android permission.

http://developer.android.com/guide/topics/manifest/permission-element.html

岛歌少女 2024-10-15 11:13:21

为什么需要 ContentProvider?内容提供商的主要目的是共享数据。如果您想以您提到的方式与您的其他应用程序共享数据,也许您可​​以使用 Android 的远程服务进行数据访问。这不像内容提供商那样好,但我对您的用例没有其他想法。

Why do you need the ContentProvider? The main purpose of content providers is sharing data. If you want to share data with other apps from yours in that way you mentioned, maybe you could use Androids Remote Services for data access. It is not that nice way as with Content Providers, but i have no other idea with your use case.

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