用于加密存储的自定义 ContentProvider
我有一些加密存储(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
ContentProvider 无法直接显示错误消息,但它可以抛出 RuntimeException,并且您可以将所需的任何消息写入 RuntimeException。 RuntimeException 将被打包并发送给调用者,无论调用者是谁,都由他们来处理代码中的异常。
我不是 100% 清楚你所说的“仅当工作/启动我的应用程序时”是什么意思。不幸的是,ContentProvider 没有一种与外界通信的简单方法:您无法绑定到服务、发送意图、获取应用程序对象等。如果您的 ContentProvider 在与以下相同的进程(因此相同的 DalvikVM)中运行如果您的应用程序可以通过公共静态字段和方法相互通信,例如:
请参阅 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:
See http://developer.android.com/guide/topics/manifest/provider-element.html#proc for info on controlling ContentProvider process.
Good Luck.
我不确定我是否完全理解您的问题,因此这个答案可能不适合您。
如果您希望用户能够选择哪些应用程序可以访问数据,请查看定义您自己的权限,其他应用程序可以像任何其他 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
为什么需要 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.