Content Providers.

Slides:



Advertisements
Similar presentations
Programming with Android: Data management
Advertisements

ListView Examples. Basic Steps for Creating a Listview 1.Create a layout (e.g., a LinearLayout), with elements for –the ListView (
Android – CoNTENT PRoViders
SQLite in Mobile Apps by Dan Youberg. Overview Many well known applications and Internet browsers use SQLite due to its very small size (~250 Kb). Also.
ContentProviders.  Databases for reading & writing data  Support typical database operations  e.g., query, insert, update & delete.
Cosc 5/4730 Android Content Providers and Intents.
컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android.
CONTENT PROVIDER. Content Provider  A content provider makes a specific set of the application's data available to other applications => Share data to.
Cosc 5/4730 Android and Blackberry SQLite. For the sql language syntax, please see SQlite documentation –
CS378 - Mobile Computing Persistence - SQLite. Databases RDBMS – relational data base management system Relational databases introduced by E. F. Codd.
Data Persistence in Android
SQLite Database. SQLite Public domain database – Advantages Small (about 150 KB) – Used on devices with limited resources Each database contained within.
Database Rung-Hung Gau Department of Computer Science and Engineering
Data Storage: Part 3 (SQLite)
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Content Providers & Services.
ContentProviders. SQLite Database SQLite is a software library that implements aself- contained, serverless,zero- configuration,transactionalSQL database.
ANDROID CONTENT PROVIDERS Peter Liu School of ICT, Seneca College.
Lec 04 Content Providers Adapters CursorLoaders Advanced Debugging.
Content providers Accessing shared data in a uniform way 1Content providers.
Cosc 5/4730 Android Content Providers and Intents.
Data Storage: Part 4 (Content Providers). Content Providers Content providers allow the sharing of data between applications. Inter-process communication.
CS378 - Mobile Computing Content Providers And Content Resolvers.
COMP 365 Android Development.  Manages access from a central database  Allows multiple applications to access the same data.
CSE 486/586, Spring 2012 CSE 486/586 Distributed Systems Recitation.
Android Content Providers In Android security model, one application cannot directly access (read/write) other application's data. Every application has.
JDBC. JDBC stands for Java Data Base Connectivity. JDBC is different from ODBC in that – JDBC is written in Java (hence is platform independent, object.
COMP 365 Android Development.  Every android application has a manifest file called AndroidManifest.xml  Found in the Project folder  Contains critical.
Address Book App 1. Define styles   Specify a background for a TextView – res/drawable/textview_border.xml.
9 Persistence - SQLite CSNB544 Mobile Application Development Thanks to Utexas Austin.
JDBC. Java.sql.package The java.sql package contains various interfaces and classes used by the JDBC API. This collection of interfaces and classes enable.
Persistence Dr. David Janzen Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution 2.5 License.
SQLite (part deux) 1 CS440. Traditional Model View Controller (MVC) CS440 2.
Database Management System. DBMS A software package that allows users to create, retrieve and modify databases. A database is a collection of related.
SQLite DB Storing Data in Android RAVI GAURAV PANDEY 1.
Android - SQLite Database 12/10/2015. Introduction SQLite is a opensource SQL database that stores data to a text file on a device. Android comes in with.
SQlite. SQLite is a opensource SQL database that stores data to a text file on a device. Android comes in with built in SQLite database implementation.
CSE 486/586, Spring 2014 CSE 486/586 Distributed Systems Android Programming Steve Ko Computer Sciences and Engineering University at Buffalo.
INFORMATION TECHNOLOGY DATABASE MANAGEMENT. A database is a collection of information organized to provide efficient retrieval. The collected information.
Address Book App 1 Fall 2014 CS7020: Game Design and Development.
David Sutton USING CONTENT PROVIDERS. TOPICS COVERED THIS WEEK  Persistence  Introduction to databases  Content providers  Cursors  Cursor adapters.
CHAPTER 9 File Storage Shared Preferences SQLite.
By: Eliav Menachi.  On Android, all application data (including files) are private to that application  Android provides a standard way for an application.
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Data Storage in Android Димитър Н. Димитров. Why talk about data? Why not 3D graphics or network connectivity? Data as fundamental term in computer science.
Database Programming Code Dissection. Layered Approach Presentation (Activity) DbSampleActivity.java DataAccess (DataSource) CommentsDataSource.java MySQLiteHelper.java.
1. 2 The Address Book app provides convenient access to contact information that’s stored in a SQLite database on the device. You can: scroll through.
CS371m - Mobile Computing Persistence - SQLite. 2 In case you have not taken 347: Data Management or worked with databases as part of a job, internship,
Data Persistence Chapter 9. Objectives Learn about data storage methods Understand use of Shared Preferences Understand file-based storage and the differences.
CS499 – Mobile Application Development
Making content providers
Data Storage: Part 3 (SQLite)
Content provider.
Cosc 5/4730 Sqlite primer.
SQL Key Revision Points.
Android Content Providers & SQLite
Data Storage: Part 4 (Content Providers)
Content Providers And Content Resolvers
SQLite in Android Landon Cox March 2, 2017.
Mobile Application Development BSCS-7 Lecture # 18, 19
Android Application SQLite 1.
CS499 – Mobile Application Development
Content Providers.
CIS 470 Mobile App Development
CMPE419 Mobile Application Development
CS371m - Mobile Computing Persistence - SQLite.
CIS 470 Mobile App Development
Android Developer Fundamentals V2
SQLLite and Android.
Lecture 8: Database Topics: Basic SQLite Operations.
Mobile Programming Dr. Mohsin Ali Memon.
Presentation transcript:

Content Providers

Objectives What are content providers? How to use a content provider in Android How to create your own content provider

Motivation Different ways to persist data, e.g., shared preferences, files, and SQLite but, accessible only by the package that created it Various persistent data from Android, e.g. Browser: browser bookmarks, borwser history, etc. CallLog: missed calls, call details, etc. Contacts: contact details MediaStore: audio, video, and images Setting: device's settings and preferences Q: How to share these data across packages and applications in a uniform way?

Content Provider: Sharing Data In Android Provides a consistent, uniform programming interface for sharing data Can be thought of as a data store, e.g., query, edit, add, and delete But unlike database, can be stored in many different ways Built-in vs user-defined

What API Or Facility? Naming a data store (URI) Querying a data store (query, Cursor) Table view of data store Inserting a new record (insert) Deleting an existing record (delete) Updating an existing record (update)

Querying Content Providers Use a query string in the form of URI content://<authority>/<data_path>/<id> <authority>: name of content provider, e.g., contacts for built-in Contacts content provider edu.utep.cs.cs4390.grade for user-defined <data_path>: specifies the kind of data requested, e.g., content://contacts/people <id>: specifies the specific record requested, e.g., content://contacts/people/2 <-- second record

Examples content://media/internal/images content://media/external/images content://call_log/calls content://browser/bookmarks

Querying Use the query method of ContentResolver Cursor query(URI uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) uri: content to retrieve projection: list of columns to return; null for all columns selection: filter declaring which rows to return, formatted as an SQL WHERE clause; null for all rows Use SQL operators: =, <>, >, <, >=, <=, between, like, in selectionArgs: args for "?s" in selection sortOrder: order of rows, formatted as an SQL ORDER BY clause e.g., “name asc” and “name desc”

Example Uri allContacts = Uri.parse("content://contacts/people"); Cursor c = getContentsResolver().query(allContacts, null, null, null, null); if (c.moveToFirst()) { do { String id = c.getString(c.getColumnIndex( ContactsContract.Contacts._ID)); String name = c.getString(c.getColumnIndex( ContactsContract.Contacts.DISPLAY_NAME)); ...use id and name .... } while (c.moveToNext()); } *Note that ContentsResolver.query is a synchronous call. *Can use a CursorAdapter class such as SimpleCursorAdapter to display results in an AdapterView such as ListView.

Cursor Class Interface providing random read-write access to the result set returned by a database query int getColumnCount(): total number of columns int getColumnIndex(String): zero-based index for the column name String getColumnName(int): column name for given index String[] getColumnNames() int getCount(): number of rows ... getBlob(int), getDouble(int), getInt(int), ... int getType(int) boolean isFirst(), isLast() boolean moveToFirst(), moveToLast(), moveToNext(), moveToPrevious(), moveToPosition(int) void registerContentObserver(ContentObserver) ...

CursorLoader: Querying Asynchronously in a new thread Uri allContacts = Uri.parse("content://contacts/people"); CursorLoader cursorLoader = new CursorLoader(this, allContacts, null, null, null, null); Cursor c = cursorLoader.loadInBackground(); if (c.moveToFirst()) { do { String id = c.getString(c.getColumnIndex( ContactsContract.Contacts._ID)); String name = c.getString(c.getColumnIndex( ContactsContract.Contacts.DISPLAY_NAME)); ...use id and name .... } while (c.moveToNext()); }

Predefined Query String Constants Uri allContacts = Uri.parse("content://contacts/people"); Uri allContacts = ContactsContract.CONTENT_URI Browser.BOOKMARKS_URI Browser.SEARCHES_URI CallLog.CONTENT_URI MediaStore.Images.Media.INTERNAL_CONTENT_URI MediaStore.Images.Media.EXTERNAL_CONTENT_URI Settings.CONTENT_URI Use withAppendedId method to retrieve a particular row, e.g., ContentUris.withAppendedId(ContactContract.Contacts.CONTENT_URI,1);

Inserting, Updating and Deleting Use the insert, update, and delete methods of ContentResolver Uri insert (Uri uri, ContentValues values) int update (Uri uri, ContentValues values, String where, String[] selArgs) int delete (Uri url, String where, String[] selectionArgs) *Refer to API documents of ContentValues and ContentResolver

Creating User-Defined Content Providers Extend the ContentProvider class and overwrite: getType(): returns MIME type of the data onCreate(): called when the provider is started query(): query and return a Cursor object insert(): insert a new record delete(): delete an existing record update(): update an existing record Need to register the content provider in the manifest file, e.g., <provider android:name="BooksProvider“ android:authority="edu.utep.cs.cs4390.provider.Books" />

In-Class (Pair) Write an app to find contacts matching a given (partial) name Display the name and phone number of matching contacts Name: Jason_______ Found: … Find