content provider in_android
TRANSCRIPT
![Page 1: Content provider in_android](https://reader036.vdocuments.site/reader036/viewer/2022062821/588734bb1a28abc0748b5a79/html5/thumbnails/1.jpg)
Content Provider In Android
Presented By:Priti Telmore
![Page 2: Content provider in_android](https://reader036.vdocuments.site/reader036/viewer/2022062821/588734bb1a28abc0748b5a79/html5/thumbnails/2.jpg)
Contents:
o Objectiveo Introductiono Built-in Content providero Content resolvero URIo Cursoro Project of Birthday Saver
![Page 3: Content provider in_android](https://reader036.vdocuments.site/reader036/viewer/2022062821/588734bb1a28abc0748b5a79/html5/thumbnails/3.jpg)
Lets Start With our Objective…
An Android app by default cannot access another app’s data. This is the cornerstone of Android security, the principle of sandboxing. But often, you do want an app to share some data with others. Content providers are such an interface to data so that the data cab be mashed together across apps.
• Why content providers• Using existing content providers• Creating a content provider• Intelligent data loading
![Page 4: Content provider in_android](https://reader036.vdocuments.site/reader036/viewer/2022062821/588734bb1a28abc0748b5a79/html5/thumbnails/4.jpg)
Introduction:• A Content Provider is an
application component that shares data with other application.
• Various system content providers manage the users contacts, call logs etc.
• Typically a content provider presents data as one or more tables, similar to tables in a database.
![Page 5: Content provider in_android](https://reader036.vdocuments.site/reader036/viewer/2022062821/588734bb1a28abc0748b5a79/html5/thumbnails/5.jpg)
How to Access ?Content Provider
Cursor Content Resolver
Cursor Adapter ListView
Activity
![Page 6: Content provider in_android](https://reader036.vdocuments.site/reader036/viewer/2022062821/588734bb1a28abc0748b5a79/html5/thumbnails/6.jpg)
Built-in Content Provider:
Content Provider
![Page 7: Content provider in_android](https://reader036.vdocuments.site/reader036/viewer/2022062821/588734bb1a28abc0748b5a79/html5/thumbnails/7.jpg)
Content Resolver:A client application accesses the data from a content provider with a Content Resolver object.The content resolver object provides - query(),insert(),update() and delete() methods for accessing data from a content provider.
Content Resolver URI
Content Provider
Query()Insert()Update()Delete()
![Page 8: Content provider in_android](https://reader036.vdocuments.site/reader036/viewer/2022062821/588734bb1a28abc0748b5a79/html5/thumbnails/8.jpg)
URI:• Uniform Resource
Identifier.• A Content URI is a URI
that identifies data in a provider.
• When you call a client method to access a table in a provider, the content URI for the table is one of the arguments.
content://com.example.provider/articles
Scheme Authority Path
1. content://browser/bookmarks
2. content://contacts/people
3. content://contacts/people/3
4. content://media/internal/images
![Page 9: Content provider in_android](https://reader036.vdocuments.site/reader036/viewer/2022062821/588734bb1a28abc0748b5a79/html5/thumbnails/9.jpg)
CURSOR:Cursor is an interface that provides random read-write access to the result of a database query from a content provider.
A cursor is a collection of rows, Random means (you can move forward and backwards)
All field access methods are based on column number. You have to convert column name to a column number first
You can also find size / traverse result set easily.Cursor cur;for( cur.moveToFirst(); !cur.isAfterLast(); cur.moveToNext()) { }
![Page 10: Content provider in_android](https://reader036.vdocuments.site/reader036/viewer/2022062821/588734bb1a28abc0748b5a79/html5/thumbnails/10.jpg)
BIRTHDAY_SAVER APP USING CONTENT PROVIDER:
![Page 11: Content provider in_android](https://reader036.vdocuments.site/reader036/viewer/2022062821/588734bb1a28abc0748b5a79/html5/thumbnails/11.jpg)
![Page 12: Content provider in_android](https://reader036.vdocuments.site/reader036/viewer/2022062821/588734bb1a28abc0748b5a79/html5/thumbnails/12.jpg)
![Page 13: Content provider in_android](https://reader036.vdocuments.site/reader036/viewer/2022062821/588734bb1a28abc0748b5a79/html5/thumbnails/13.jpg)
activity_main.xml :This is the layout of project
![Page 14: Content provider in_android](https://reader036.vdocuments.site/reader036/viewer/2022062821/588734bb1a28abc0748b5a79/html5/thumbnails/14.jpg)
![Page 15: Content provider in_android](https://reader036.vdocuments.site/reader036/viewer/2022062821/588734bb1a28abc0748b5a79/html5/thumbnails/15.jpg)
Birthday.java :This is the java class for content provider and database
![Page 16: Content provider in_android](https://reader036.vdocuments.site/reader036/viewer/2022062821/588734bb1a28abc0748b5a79/html5/thumbnails/16.jpg)
![Page 17: Content provider in_android](https://reader036.vdocuments.site/reader036/viewer/2022062821/588734bb1a28abc0748b5a79/html5/thumbnails/17.jpg)
![Page 18: Content provider in_android](https://reader036.vdocuments.site/reader036/viewer/2022062821/588734bb1a28abc0748b5a79/html5/thumbnails/18.jpg)
![Page 19: Content provider in_android](https://reader036.vdocuments.site/reader036/viewer/2022062821/588734bb1a28abc0748b5a79/html5/thumbnails/19.jpg)
![Page 20: Content provider in_android](https://reader036.vdocuments.site/reader036/viewer/2022062821/588734bb1a28abc0748b5a79/html5/thumbnails/20.jpg)
![Page 21: Content provider in_android](https://reader036.vdocuments.site/reader036/viewer/2022062821/588734bb1a28abc0748b5a79/html5/thumbnails/21.jpg)
![Page 22: Content provider in_android](https://reader036.vdocuments.site/reader036/viewer/2022062821/588734bb1a28abc0748b5a79/html5/thumbnails/22.jpg)
![Page 23: Content provider in_android](https://reader036.vdocuments.site/reader036/viewer/2022062821/588734bb1a28abc0748b5a79/html5/thumbnails/23.jpg)
Output: 1. First insert the data
![Page 24: Content provider in_android](https://reader036.vdocuments.site/reader036/viewer/2022062821/588734bb1a28abc0748b5a79/html5/thumbnails/24.jpg)
Output: 2. Then press ‘Add a new Birthday’ button it will toast the no of data inserted.
![Page 25: Content provider in_android](https://reader036.vdocuments.site/reader036/viewer/2022062821/588734bb1a28abc0748b5a79/html5/thumbnails/25.jpg)
Output: 3. To show the inserted data press ‘Show all Birthday’ buttonIt will show all the birthdays inserted.
![Page 26: Content provider in_android](https://reader036.vdocuments.site/reader036/viewer/2022062821/588734bb1a28abc0748b5a79/html5/thumbnails/26.jpg)
Output: 4. By pressing ‘Delete all Birthday’ button All the records will be deleted and shown by toasting.
![Page 27: Content provider in_android](https://reader036.vdocuments.site/reader036/viewer/2022062821/588734bb1a28abc0748b5a79/html5/thumbnails/27.jpg)
THANK YOU