开发者

How to pass binary data between two apps using Content Provider?

I need to pass some binary data between two android apps using Content Provider (sharedUserId is not an option).

I would prefer not to pass the data (a savegame stored as a file, small in size < 20k) as a file (ie. overriding openFile()) since this would necessitate some complicated temp-file scheme to cope with concurrency with several content provider accesses and a running game.

I would like to read the file into memory under a mutex lock and then pass the binary array in the simplest way possible. How do I do this?

It seems creating a file in memory is not a possibility due to the return t开发者_如何学Goype of openFile().

query() needs to return a Cursor. Using MatrixCursor is not possible since it applies toString() to all stored objects when reading it.

What do I need to do? Implement a custom Cursor? This class has 30 abstract methods. Do I read the file, put it in a SQLite db and return the cursor?

The complexity of this seemingly simple task is mindboggling.


Why not giving the data as Base64 string?


Have you tried using streams? That will work

From the documentation: "If the table entry is a content: URI, you should never try to open and read the file directly (for one thing, permissions problems can make this fail). Instead, you should call ContentResolver.openInputStream() to get an InputStream object that you can use to read the data."

Link: http://developer.android.com/guide/topics/providers/content-providers.html

Maybe something like this, if you are using Intents:

protected void onActivityResult(int requestCode, int resultCode, Intent intent){
  InputStream is = getContentResolver().openInputStream(intent.getData())
...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜