1

I have been reading content providers for a while and i have seen that of two types, one is in built for eg Contacts(that i understood) and other is making our own content provider by content:// thing. Well most of the examples i have gone through are doing it in one app. I mean what is the point of using content providers then if i store data in one app and retrieving it in the same as the definition says it shares data between apps?

I am looking it as i made two projects and i used content provider in one and store some data in database. Then i make other project and get that stored data through the content :// uri . Is that what is main function of content provider? Is this thing possible? If so how? I have been asking it clear my basics.

Nano Web
  • 27
  • 1
  • 5
  • refer this http://stackoverflow.com/a/6157686/1576416 and this http://stackoverflow.com/a/14509680/1576416 – Amrut Bidri Apr 01 '15 at 05:33
  • I am still not getting how to fetch in other application. I imported the following project http://examples.javacodegeeks.com/android/core/content/contentprovider/android-content-provider-example/ . What all things i need in another project? – Nano Web Apr 01 '15 at 05:49
  • ok so your second link was helpful. – Nano Web Apr 01 '15 at 07:38

3 Answers3

1

To understand content providers you need to understand the Android Architecture first. All android apps runs in its own VM (Virtual Machine), it means when you run app 'A' and store some files or create database in it, now when you run app 'B' and create database in it.

Those two apps 'A' and 'B' do not know each other or in easy words they do not share data between them. To make data accessible one app has to share its data so other can access it. Thats where ContentProvider comes in.

Through content providers any app can expose its data to other apps which are interested in taking it.

One example is your Contact list. You can access Contact List through content provider although it is not created by you and own by Android, but it intents to share data with you, and you can access it through content providers.

Murtaza Khursheed Hussain
  • 15,176
  • 7
  • 58
  • 83
  • Yes that i understood , i want to know how it shares when i create my own content provider that too between two apps( two apps in my case means two projects separate) the various permissions both need and everything – Nano Web Apr 01 '15 at 06:02
1

I believe you are looking for information on the Content Resolver. As others pointed out, the Provider is just for sharing your app's data. When you want to access it, even in another app, you use the Content Resolver to send commands to the other App's Content Provider; insert(), update(), delete(), and query().

What you spoke of about content://URI, that's the identifier for the name of the data you are looking for in a Content Provider. The link explains Providers, Resolvers, Contracts, URIs, and how to create them.

http://www.grokkingandroid.com/android-tutorial-writing-your-own-content-provider/

wmbtech
  • 11
  • 1
0

Content providers let you centralize content in one place and have many different applications access it as needed. A content provider behaves very much like a database where you can query it, edit its content, as well as add or delete content usingg insert(), update(), delete(), and query() methods. In most cases this data is stored in an SQlite database.

I am looking it as i made two projects and i used content provider in one and store some data in database. Then i make other project and get that stored data through the content :// uri . Is that what is main function of content provider?

I think you are looking for this: http://www.vogella.com/tutorials/AndroidSQLite/article.html

Fay007
  • 2,707
  • 3
  • 28
  • 58
  • i used this http://examples.javacodegeeks.com/android/core/content/contentprovider/android-content-provider-example/ and i need to access the database in my new project. I m not getting what all things i need to do in new project to fetch these. – Nano Web Apr 01 '15 at 05:52
  • if you can share your code that would be good,cause it's really impossible to understand where is your problem @NanoWeb – Fay007 Apr 02 '15 at 06:39