Sample non-SQLite content providers

I am trying to create a content provider that uses internal storage. However, all the examples that I see on the Internet use only sqlite.

Can someone provide me with a good tutorial or an example of creating a content provider using internal storage?

+7
source share
3 answers

You can store data in files using file methods for content providers such as openTypedAssetFile (). This returns an AssetFileDescriptor (i.e. a file descriptor valid for all processes) instead of Cursor.

In general, the question is very difficult to answer. A content provider is the β€œinterface” between a data warehouse and clients. The documentation does not talk about repositories other than SQLite, because: a) the content provider model is organized along the lines of the relational database, and b) each implementation of the content provider will be different.

I hesitate to give more advice before knowing your exact requirements. You may be able to use SQLite, although you may not immediately understand why. You may also be right: SQLite is not a solution, but given more information, I could offer some ideas.

+4
source

The Android SDK examples have an example FileProvider.java that uses a ContentProvider but not a SQLite database.

+1
source

Well, I know what you are trying to do, perhaps create images, movies or, for example, with internal storage.

You can use InternalStorage to store bytes of data. If you have bytes you can just do:

String FILENAME = "hello_file"; String string = "hello world!"; FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE); fos.write(string.getBytes()); fos.close(); 

to find out:

  File file = ... OutputStream out = null; try { out = new BufferedOutputStream(new FileOutputStream(file)); ... finally { if (out != null) { out.close(); } } 

All sources are found on this and this . I can not help you further than this reason. I have never tried.

0
source

All Articles