Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Content_URI in content Provider

As per my understanding, Content Provider is a means for accessing database contents.

And to access the database, the Authority part is required. This authority part is provided by CONTENT_URI. Thus Content_URI is a means for giving authority to the database. As far as CONTENT_URI is concerened, it is generally of the form

content://com.example.transportationprovider/trains/122
______ |____________________________________|_____ |___ 
  A                      B                     C     D
Where A = Content,
      B = Authority Part
      c = Path determining what data to request
      D = specific data

Above scenario is a ideal scenario where-in we pass /trains as the only database name. But what if, i have the following content_uri:

content://com.example.transportationprovider/land/bus/133

In this case, /land/bus is the path segments.

But then internally how this data is stored in the database ? Or how content Provider interpret this data?

Please help me.

like image 243
Ashish Avatar asked Nov 22 '10 10:11

Ashish


People also ask

What is a content resolver?

What is the Content Resolver? The Content Resolver is the single, global instance in your application that provides access to your (and other applications') content providers.

What is a ContentProvider and what is it typically used for?

A content provider manages access to a central repository of data. A provider is part of an Android application, which often provides its own UI for working with the data. However, content providers are primarily intended to be used by other applications, which access the provider using a provider client object.

What are CRUD operations in Android content provider?

Four fundamental operations are possible in Content Provider namely Create, Read, Update, and Delete. These operations are often termed as CRUD operations.

How exploitable is content provider?

According to the question, A content provider component supplies data from one application to others on request. Such requests are handled by the methods of the Content Resolver class. A content provider can use different ways to store its data and the data can be stored in a database, in files, or even over a network.


1 Answers

The simple answer is that it's stored in the database however you like. Everything in in the path, and the mapping of the path to the database underneath, is defined by the writer of the ContentProvider.

More or less, the model you want to use is that you have one path per table in your database.

There are some cases where you might want some additional paths. Typically, this means exposing some alternate "view" of the database... The Contacts API provides a great example of this.

Why do you want to enforce this kind of hirearchy "land/bus"? Why not just "bus" and "train". with one SQL table each? SQL tables are not Java classes. They don't have inheritance relationships and that sort of hirearchy isn't necessary.

like image 63
jcwenger Avatar answered Oct 14 '22 04:10

jcwenger