content provider in_android

27
Content Provider In Android Presented By Priti Telmor

Upload: priti-telmore

Post on 24-Jan-2017

308 views

Category:

Mobile


0 download

TRANSCRIPT

Page 1: Content provider in_android

Content Provider In Android

Presented By:Priti Telmore

Page 2: Content provider in_android

Contents:

o Objectiveo Introductiono Built-in Content providero Content resolvero URIo Cursoro Project of Birthday Saver

Page 3: Content provider in_android

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

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

How to Access ?Content Provider

Cursor Content Resolver

Cursor Adapter ListView

Activity

Page 6: Content provider in_android

Built-in Content Provider:

Content Provider

Page 7: Content provider in_android

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

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

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

BIRTHDAY_SAVER APP USING CONTENT PROVIDER:

Page 11: Content provider in_android
Page 12: Content provider in_android
Page 13: Content provider in_android

activity_main.xml :This is the layout of project

Page 14: Content provider in_android
Page 15: Content provider in_android

Birthday.java :This is the java class for content provider and database

Page 16: Content provider in_android
Page 17: Content provider in_android
Page 18: Content provider in_android
Page 19: Content provider in_android
Page 20: Content provider in_android
Page 21: Content provider in_android
Page 22: Content provider in_android
Page 23: Content provider in_android

Output: 1. First insert the data

Page 24: Content provider in_android

Output: 2. Then press ‘Add a new Birthday’ button it will toast the no of data inserted.

Page 25: Content provider in_android

Output: 3. To show the inserted data press ‘Show all Birthday’ buttonIt will show all the birthdays inserted.

Page 26: Content provider in_android

Output: 4. By pressing ‘Delete all Birthday’ button All the records will be deleted and shown by toasting.

Page 27: Content provider in_android

THANK YOU