Want to know custom content provider example in android? we have a huge selection of custom content provider example in android information on alibabacloud.com
Requirement Analysis:
Use ContentResolver to operate the data of the content provider, display the name and phone number in listView, and carry the add and delete buttons for corresponding operationsSteps:
Adater model layer create content parser object ContentResolver define URI custom CursorAdapter implement cons
applications access, other applications can use the ContentProvider to operate the data in the specified application. ContentProvider is divided into system and custom, the system is such as contact person, picture and other data.The data operations in Android include:File, Sqlite3, Preferences, Contectresolver and ContentProvider the first three types of data operations are only for the data in this appli
Next, the android content provider-content providers (1)
Contacts provider is a powerful and flexible component in Android. It manages the data in the system address book and provides external access interfaces to access and opera
the provider
The following two steps are involved: User dictinary)
(1) Request read permission. Configure Android. Permission. read_user_dictionary in the mainfest File
(2) custom query code. There are two main processing methods: one is to display the query results and the other is to obtain the query data.
In addition, when you precisely search for a record, i
indicate the path, the type of content, that is, "Card/pin" in the example, this part can be empty.4, the last is instance identifier, is an integer that indicates the specific location of the data in the content. The URI of a content, if not instance identifier, represents the data set (collection) of the content.The
Cursor object. URI
Each contentprovider defines a unique public URI to specify its dataset. A contentprovider can contain multiple datasets and can be considered as multiple tables. In this way, multiple Uris must correspond to each dataset. These Uris must begin with the following format:
Content ://
Indicates that this uri specifies a contentprovider.
If you want to create your own contentprovider, you 'd better set the
1. Content ProviderSQLite saves each application's own database, which is inaccessible between application databases , and content Provider solves this problem.It stores data that can be accessed by individual applications, can create content Providerin its own application, or can directly use existing
identifier (17), used to indicate the path, the type of the content, that is, "Card/pin" in the example, this part can be empty.
4, the last is instance identifier, is an integer, indicating the exact location of the data in the content. The URI of a content, if there is no instance identifier, represents the data set
Content Provider provides a unified interface for different applications to access data, and this article describes the knowledge that is used to test content Provider in the Android test pack.
The basic class for testing the content
ContentProvider to other applications to expose the database information as an example to explain the basic use of contentprovider. The creation and use of SQLite database in Android, this article is no longer introduced, not clear please read this articlethe simple and practical application of SQLite databaseAssuming that the reader has learned the use of the SQLite database and has established the databa
Create a Content Provider
The content provider Manages access to the central data warehouse. You implement a provider that implements one or more classes in an Android application, and adds some elements in the manifest file. You
. Although the use of other methods can also share data, but the way data access will vary depending on how the data is stored, such as: the use of file-based data sharing, the need for file operations to read and write data, the use of sharedpreferences shared data, You need to read and write data using the Sharedpreferences API. The benefit of using ContentProvider to share data is to unify the way data is accessed.Steps for using the ContentProvider class1,
We learned how to access data from other applications in our own programs. Overall, the idea is very simple, just need to get the content URI of the application, and then use Contentresolver for crud operation. But have you ever wondered how the applications that provide the external access interface implement this functionality? How do they ensure data security so that private data is not leaked? 7.3.1 steps to create a
Content Provider is an abstract data encapsulation and data access mechanism. For example, SQLite is a data source provided by Android devices and can be encapsulated into a content provider. To read and write data through
in ContentProviderContentProvider Scheme for (content provider) is already defined by Android,scheme: content://The host name (or authority) is used to uniquely identify this contentprovider, and the external caller can find it based on this identity.Pathcan be used to represent the data we want to manipulate, and the
, categorized by the installation package. We can take a look at those packages with the SQLite database under the ls–r/data/data/*/databases . For example, some DB built into Android.These *.db files are on the SQLite database. The Android database is usually created at the time of the first visit. To approach the database using:sqlite3 /data/data/Here are some common SQLite commands:Sqlite>.exit Exit SQLi
VND2. If the content URI ends with a path, then android.cursor.dir/is followed, and if the content URI ends with an ID, then the android.cursor.item/is followed up3, finally connected to the Vnd.Therefore, for content://com.example.app.providder/table1 this content URI, its corresponding MIME type can be written as:Vn
activity, and the service provider activity should meet the conditions. Then it is about the Android system. It is responsible for identifying qualified activity service providers and giving intent to the activity service providers. Then, this acitivity performs corresponding operations based on the remaining information in the intent.
As shown above, intent contains two parts:
1. Information of the activi
The examples in this article describe how Android programming uses content providers to store them. Share to everyone for your reference, specific as follows:
The primary role of content providers (ContentProvider) is to share data externally, and if data is shared externally by content providers, other applications c
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.