Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to access content providers using Room? #13

Closed
ghost opened this issue May 21, 2017 · 10 comments
Closed

How to access content providers using Room? #13

ghost opened this issue May 21, 2017 · 10 comments

Comments

@ghost
Copy link

ghost commented May 21, 2017

One of the most common content provider that is accessed is Android's MediaStore. How do I access data of Android MediaStore using Room?

@yigit
Copy link
Contributor

yigit commented May 21, 2017

Unfortunately no. Room is designed to work with SQLite database.

@yigit yigit closed this as completed May 21, 2017
@gajicm93
Copy link

Room is not meant for it, but I was wondering the same thing regarding the Live Data. Could you give examples how to load MediaStore/ContactsProvider with live data, instead of Loaders?

I'll be implementing this soon, and I'd like to use LiveData instead of Loaders, and of course it's also important that my LiveData gets notified of any change in the MediaStore, which somehow already works with the Loader.. @yigit Thanks!

@Lingviston
Copy link

One more thing is SyncAdapter. Of course we can update Room database directly from it and all associated LiveData objects should get the update. But what about the ContentProvider instances connected to the same SQLite db? What to do with ContentProviderClient, which is passed into a SyncAdapter instance?

@bpappin
Copy link

bpappin commented Jul 13, 2018

I'm in the same boat @Lingviston is. I'm migrating to Room, but without a content provider, the sync engine won't run.

@Lingviston
Copy link

@bpappin it is generally OK, because Room is not a replacement for ContentProviders. But since Room can be used by ContentProvider I think it should come with helper classes which allow avoid writing lots of boilerplate code when you need to communicate with Room DB in your own app through the CP protocol.

@KryptKode
Copy link

@gajicm93 Did you manage to implement using live data to load MediaStore/ContactsProvider?

@gajicm93
Copy link

@KryptKode I think I didn't end up trying it, but if you need it, I would recommend to start by looking into Room generated code to see how they convert SQL queries into LiveData, and write the same code manually for MediaStore. If you need any additional help just send me a message.

Screen Shot 2019-08-15 at 15 55 53

@vyadav33e
Copy link

Unfortunately no. Room is designed to work with SQLite database.

So Room cannot be used with content providers like call logs,contacts etc?

@KryptKode
Copy link

Yes @vyadav33e

@ahmadtahir1919
Copy link

I have two Application, Application A is main App and Application B is child Application i have database in Application A(main app) now i want to use Application A database into Application B and use all data in Application B i found some answers but all answers are SQLite with ContentProvider but not for Room and no any example found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants