CS371m - Mobile Computing. Content Providers And Content Resolvers

Similar documents
CS378 -Mobile Computing. Content Providers

Content Provider. Introduction 01/03/2016. Session objectives. Content providers. Android programming course. Introduction. Built-in Content Provider

ContentProvider & ContentResolver ContentResolver methods CursorLoader Implementing ContentProviders

Automatically persisted among application sessions

Mobile Programming Lecture 10. ContentProviders

Android Programming - Jelly Bean

Lecture 2 Android SDK

Mobile Application Development Android

CS Android. Vitaly Shmatikov

Mobile Application Development Android

Learn about Android Content Providers and SQLite

Android System Architecture. Android Application Fundamentals. Applications in Android. Apps in the Android OS. Program Model 8/31/2015

Android Application Development 101. Jason Chen Google I/O 2008

Mobile Application Development Android

CS378 -Mobile Computing. Intents

CMSC436: Fall 2013 Week 4 Lab

M.C.A. Semester V Subject: - Mobile Computing (650003) Week : 2

Mobile Application Development Android

CS371m - Mobile Computing. Persistence - SQLite

Introduction. Lecture 1. Operating Systems Practical. 5 October 2016

Required Core Java for Android application development

Android. Operating System and Architecture. Android. Screens. Main features

Topics Covered in the Android Apps Development Training

Syllabus- Java + Android. Java Fundamentals

Android Application Development

Data storage and exchange in Android

Android Programming in Bluetooth Cochlea Group

A Tour of Android. and some of it s APIs. Bryan Noll

Android Components. Android Smartphone Programming. Matthias Keil. University of Freiburg

Accelerating Information Technology Innovation

The Basis of Data. Steven R. Bagley

ANDROID SYLLABUS. Advanced Android

MC Android Programming

ContentProviders. CS 282 Principles of Operating Systems II Systems Programming for Android

Minds-on: Android. Session 1

Android Components Android Smartphone Programming. Outline University of Freiburg. Data Storage Database University of Freiburg. Notizen.

Praktikum Mobile und Verteilte Systeme. Android-Basics. Prof. Dr. Claudia Linnhoff-Popien André Ebert, Sebastian Feld

Android-Basics. Praktikum Mobile und Verteilte Systeme. Prof. Dr. Claudia Linnhoff-Popien André Ebert, Sebastian Feld

SHWETANK KUMAR GUPTA Only For Education Purpose

Security Philosophy. Humans have difficulty understanding risk

How-to s and presentations. Be prepared to demo them in class. ons

CORE JAVA& ANDROID SYLLABUS

Android App Development

Android Programming (5 Days)

Object-Oriented Databases Object-Relational Mappings and Frameworks. Alexandre de Spindler Department of Computer Science

Android Overview. Most of the material in this section comes from

ANDROID DEVELOPMENT. Course Details

ITG Software Engineering

Android Fundamentals - Part 1

CS371m - Mobile Computing. Responsiveness

Presentation Outline 10/16/2016

Understand applications and their components. activity service broadcast receiver content provider intent AndroidManifest.xml

ORACLE UNIVERSITY AUTHORISED EDUCATION PARTNER (WDP)

Android Online Training

Android Ecosystem and. Revised v4presenter. What s New

Lecture 08. Android Permissions Demystified. Adrienne Porter Felt, Erika Chin, Steve Hanna, Dawn Song, David Wagner. Operating Systems Practical

Ariadnima - Android Component Flow Reconstruction and Visualization

CS378 -Mobile Computing. Persistence -SQLite

Java Training Center - Android Application Development

Android App Development. Ahmad Tayeb

Working with a Module

Linked data from your pocket

Lecture 1 - Introduction to Android

Android App Development. Muhammad Sharjeel COMSATS Institute of Information Technology, Lahore

CS371m - Mobile Computing. Persistence

Android. Mobile operating system developed by Google A complete stack. Based on the Linux kernel Open source under the Apache 2 license

Produced by. Mobile Application Development. David Drohan Department of Computing & Mathematics Waterford Institute of Technology

CSCU9YH: Development with Android

JAVA+ANDROID CURRICULUM 6 WEEKS. INTRODUCTION TO JAVA Understanding Requirement: Why Java Why Java is important to the Internet JAVA on LINUX Platform

Produced by. Mobile Application Development. David Drohan Department of Computing & Mathematics Waterford Institute of Technology

Introduction to Programming Using Java (98-388)

App Development for Smart Devices. Lec #5: Content Provider

INTRODUCTION COS MOBILE DEVELOPMENT WHAT IS ANDROID CORE OS. 6-Android Basics.key - February 21, Linux-based.

Android. Michael Greifeneder. Image source: Android homepage

Android permissions Defining and using permissions Component permissions and related APIs

Course Description. Learn To: : Intro to JAVA SE7 and Programming using JAVA SE7. Course Outline ::

LTBP INDUSTRIAL TRAINING INSTITUTE

Android-Basics. Praktikum Mobile und Verteilte Systeme

Another difference is that the kernel includes only the suspend to memory mechanism, and not the suspend to hard disk, which is used on PCs.

Minds-on: Android. Session 2

Compaq Interview Questions And Answers

Wirtschaftsinformatik Skiseminar ao. Prof. Dr. Rony G. Flatscher. Seminar paper presentation Dennis Robert Stöhr

Android. (XKE Mars 2009) Erwan Alliaume.

PAPER ON ANDROID ESWAR COLLEGE OF ENGINEERING SUBMITTED BY:

Activities and Fragments

Lambda and "Functional" Programming. June 28, 2017

Implementing a Download Background Service

Android Application Development Course 28 Contact Hours

The World of Android Development

Mobile Computing LECTURE # 2

Lecture 1 Introduction to Android. App Development for Mobile Devices. App Development for Mobile Devices. Announcement.

Spring Lecture 5 Lecturer: Omid Jafarinezhad

CS371m - Mobile Computing. Persistence - Web Based Storage CHECK OUT g/sync-adapters/index.

ANDROID TRAINING PROGRAM COURSE CONTENT

Android framework. How to use it and extend it

Answers to Exercises

Programming Android UI. J. Serrat Software Design December 2017

Application Development for Mobile and Ubiquitous Computing

SharedPreference. <map> <int name="access_count" value="3" /> </map>

Mobile Computing. Introduction to Android

Transcription:

CS371m - Mobile Computing Content Providers And Content Resolvers

Content Providers One of the four primary application components: activities content providers / content resolvers services broadcast receivers 2

Android Applications Recall Each application runs as a different user on the OS private files, user id, separate process with its own instance of the Dalvik VM Content Providers and Content Resolvers act as a bridge between applications to share data 3

Clciker Which are you more likely to interact with directly in your apps? A. A Content Resolver B. A Content Provider 4

Content Providers Standard mechanism / interface to allow code in one process (app, content resolver) to access data from another process (app, content provider) example, app to remind you to call certain people content resolver accesses call log to check last contact manage access to a structured data encapsulate the data and provide mechanisms for defining data security 5

Content Provider - Content Resolver Calendar App Data Your App Call Log Data 6

Content Providers Many of the built in applications on devices have content providers to allow other apps to access data Examples of apps with content providers AlarmClock CalendarContract (API level 14) CallLog (sent and received calls) ContactsContract MediaStore (audio / visual data) UserDictionary VoicemailContract many, many more http://developer.android.com/reference/android/provider/package-summary.html 7

Content Providers Provide access to a central data repository ability to read and write to centralized data data presented by Content Provider in the form of a table like table from relational database Each row in data table one "piece" of data in repository 8

Example Table Data from user dictionary primary key optional _ID column required to bind data from provider to a ListView 9

ConentProvider Theory Abstraction facilitated by having URI for data from content provider content://<more to follow> is the URI for the content Don't know where data (content is actually stored) sqlite data base, flat file, server accessible via network content://contacts/people 10

Listing Content Providers Simple to list all ContentProviders available on Device / System Varies from device to device 11

USING CONTENT PROVIDERS AND CONTENT RESOLVERS 12

Accessing Data Use a ContentResolver client object in your app ContentResolver communicates with ContentProvider provides "CRUD" functionality, Create, Retrieve, Update, Delete matching methods in Content Resolver / Content Provider example: query() method Create a cursor via content resolver to move through rows of table 13

Using Content Providers Unlike Activities, Services, and Broadcast Receivers we won't declare ContentResolvers in our AndroidManifest.xml file In practice you may not even realize you are using a ContentProvider we call the getcontentresolver() method inherited from Context and then the query method on the returned ContentResolver 14

Accessing Content via Provider Example: Exploring Images on a device MediaStore.Images.Media class presents various Content Providers get the cursor: 15

Query 5 parameters uri for content, URI look at class documentation, generally a constant projection, String[] what columns to get from the table, null = all, can be inefficient selection clause, String filter, what rows to include, a SQL WHERE clause selection args, String[] replace?'s in selection with these sortorder, String how to order the rows 16

Accessing Content via Provider After obtaining cursor: result: 17

MediaStore.Images.Media Columns from table: According to Logcat: [_id, _data, _size, _display_name, mime_type, title, date_added, date_modified, description, picasa_id, isprivate, latitude, longitude, datetaken, orientation, mini_thumb_magic, bucket_id, bucket_display_name, width, height] 18

MediaStore.Images.Media Columns documented in ContentProvider classes and interfaces 19

MediaStore.Images.Media Columns 20

Selection Columns Limit Columns returned with projection argument to query method that creates Cursor 21

Showing Data in Logcat 22

Cursor The ContentResolver query method creates and returns a Cursor Similar to a Database Cursor similar to Scanner or Iterator Move through the data (rows) one element at a time Process data with loop or bind cursor to a ListView with an Adapter 23

Getting Data from Row Must determine what type column data is in, use getx method refer to constants from ContentProvider class careful - some INTEGERS longs 24

Using Selection Criteria Example gets rows in table the selection criteria and selection args allow picking only certain rows essentially an SQL WHERE clause http://www.w3schools.com/sql/sql_where.asp specify a criteria that must be met? is value filled in with selectionargs multiple criteria possible, AND, OR, NOT 25

Using Selection Criteria Instead of selecting all rows, only select rows with image size greater than some minimum value recall: null, null returns all rows 26

Result 27

Why selectioncriteria and selectionargs?? Why not just say: selectioncriteria = "MediaStore.Images.Media.SIZE > 1750000" SECURITY If selection criteria is based on user input, user could insert malicious SQL statements to attempt to delete data base table example: " MediaStore.Images.Media.SIZE > " + "nothing; DROP TABLE *;" 28

Displaying Data in ListView Specify columns to get from ContentProvider Create view that will hold data one row Obtain cursor from ContentProvider Use ListAdapter to convert data from Cursor to Views Sub class adapter to format text 29

Display Data from ContentProvider 30

Display Data from ContentProvider rest of populatelistview from ListActivity 31

Subclass Adapter 32

Results 33

Permissions Using certain content providers require an application request permission Calendar and Contact permissions are catergorized as Dangerous Permissions Must request at runtime 34

Content Provider Capabilities Possible to update, insert, and delete data via a ContentProvider CRUD insert, update, and delete methods part of ContentResolver class for example insert new calendar data or modify existing calendar data 35

ContentProviders and Intents Some Content Providers have common activities created Intent Filters to handle the operation Example Calendar has Intent Filter so other applications can add events opens form with data filled in, finish creation, go back to original app, event added to calendar 36

Calendar Event Add 37

Single Data Elements Sometimes you don't want all the data from a Content Provider you want one piece of data, one row from the table must have the ID value of the row and the Content Provider must support this functionality 38

SPECIAL PROVIDERS AND CONTRACTS 39

Calendar Provider and Contact Provider Special providers Calendar and Contact data considered central to user experience Android has built in components to work with Calendar and Contact data 40

Contacts Provider Built to accommodate a wide range of data and manage as much data as possible for each contact flexible, powerful, complicated provides contract classes to access and modify Contacts data 41

Contracts Some apps that have content providers provide Contract classes "help work with Content provider Uris, column names, intent actions, and other features of the content provider" Adds a layer of abstraction and encapsulation 42

Contacts Contract Many nested classes Provide information on the tables in the content provider and some convenience methods for accessing that data 43

Contacts Contract Example of abstraction Possible to create cursor and pull out the last time a contact was contacted 44

Calendar and Contacts Providers The Calendar and Contacts data used by many of the apps on the device Each have their own APIs to perform CRUD operations create, read, update, delete Calendar provider has tables for Calendars, Events, Instances, Attendees, Reminders Contact provider manages as much data for each contact as possible leading to a complex organization multiple contract classes for retrieval and modification of contact data 45

CREATING CONTENT PROVIDERS 46

Creating ContentProvider You may need / want to provide a ContentProvider if: You want to offer complex data or files to other applications. You want to allow users to copy complex data from your app into other apps. You want to provide custom search suggestions using the search framework. Want the ability to change how you store data without changing how your own app accesses the data 47

LOADERS 48

Loaders Alternative approach to getting Cursor from a ContentProvider Accessing data from ContentProvider may be a lengthy operation doing this on the UI thread may lead to ANR, unresponsiveness Loader interfaces and classes used to do this on a separate thread create their own AsynchTask 49

create a loader API level 11 or greater CursorLoader ListView or ListFragment, but not ListActivity implement a class with the proper callback methods for when the CursorLoader is finished and data is ready for access public Loader<Cursor> oncreateloader(int id, Bundle args) public void onloadfinished(loader<cursor> loader, Cursor data) public void onloaderreset(loader<cursor> loader) 50