开发者

Custom ContentProvider for encrypted storage

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 - i开发者_如何学运维n 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.


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜