2

my android application is handling a large database of bus passage time and we would like to allow others application to be able to display certains bus passage time. We would like to use a content provider to do that. Most example seems to be about using an SQL database, but... we use some custom text file. I was wondering what would be the best way to do that. I was thinking I could use a Content Provider and implement the Cursor interface on a custom object that I would manually fill with my text data. Would this be possible ? Anyone have a better idea (excluding changing to SQL lite of course) ?

Thanks in advance.

Jean-Philippe Jodoin
  • 4,536
  • 1
  • 25
  • 28

1 Answers1

3

Would this be possible ?

Sure. ConetntProvider is, in effect, a facade, not dictating all that much about the internal implementation.

The key will be documentation. If you are not using SQLite as a data store, you most likely will not be supporting full WHERE clauses for query() and such. Hence, you need to make sure that whatever you do support for WHERE clauses, available columns, and the like, you document it well, so developers integrating with your content provider know how to do it. Otherwise, they may make faulty assumptions.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Even if I hack around with URI, how can I dodge Cursor ? (using new DB, Realm) – Dexter Dec 25 '14 at 14:29
  • @Dexter: You cannot "dodge Cursor". Realm is not designed to be put behind a `ContentProvider`. You would have to convert Realm results into a `MatrixCursor` or some other `Cursor` implementation. – CommonsWare Dec 25 '14 at 14:38
  • My main motive is to use CursorLoader and sync adapters. Should i implement some form of cursor or should I skip content provider totally and make custom code. I know its a vauge qstn, but what would you do in my situation. My syncing needs are pretty basic. – Dexter Dec 25 '14 at 14:49
  • @Dexter: I have not played with a sync adapter yet and so do not know how best to tie sync adapters to Realm -- sorry! – CommonsWare Dec 25 '14 at 14:53
  • Just linking "You would have to convert Realm results into a MatrixCursor" -> http://stackoverflow.com/questions/28966881/realm-share-database-between-apps – Marian Paździoch Apr 20 '16 at 10:35
  • @CommonsWare do you have any example or url which shows how to create content provider without SQL or create content provider with like mysql,oracle,h2 etc database? – Nitish Patel Sep 26 '16 at 07:02
  • @nitishpatel: "do you have any example or url which shows how to create content provider without SQL" -- see [`FileProvider`](https://github.com/android/platform_frameworks_support/blob/master/v4/java/android/support/v4/content/FileProvider.java). "create content provider with like mysql,oracle,h2 etc database?" -- neither MySQL nor Oracle run on Android. `ContentProvider` is not designed for querying remote data sources live. – CommonsWare Sep 26 '16 at 11:14