CS378 - Mobile Computing Content Providers And Content Resolvers.

Slides:



Advertisements
Similar presentations
Google Android Introduction to Mobile Computing. Android is part of the build a better phone process Open Handset Alliance produces Android Comprises.
Advertisements

1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Mgt 240 Lecture MS Excel and Access: Introduction to Databases September 23, 2004.
Mobile Application Development
컨텐트 프로바이더 박승제. Content Provider The only way to share data across applications Using content provider Use existing content providers supplied by android.
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
Chapter 14: Advanced Topics: DBMS, SQL, and ASP.NET
BUSINESS DRIVEN TECHNOLOGY
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department.
CS378 - Mobile Computing Persistence - SQLite. Databases RDBMS – relational data base management system Relational databases introduced by E. F. Codd.
Emerging Platform#4: Android Bina Ramamurthy.  Android is an Operating system.  Android is an emerging platform for mobile devices.  Initially developed.
SQLite Database. SQLite Public domain database – Advantages Small (about 150 KB) – Used on devices with limited resources Each database contained within.
Mobile Application Development with ANDROID. Agenda Mobile Application Development (MAD) Intro to Android platform Platform architecture Application building.
8 Copyright © 2004, Oracle. All rights reserved. Creating LOVs and Editors.
By Mihir Joshi Nikhil Dixit Limaye Pallavi Bhide Payal Godse.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Content Providers & Services.
Chapter 5: Investigate! Lists, Arrays, and Web Browsers.
XP New Perspectives on Microsoft Access 2002 Tutorial 51 Microsoft Access 2002 Tutorial 5 – Enhancing a Table’s Design, and Creating Advanced Queries and.
@2011 Mihail L. Sichitiu1 Android Introduction Platform Overview.
© Paradigm Publishing Inc. 9-1 Chapter 9 Database and Information Management.
ANDROID CONTENT PROVIDERS Peter Liu School of ICT, Seneca College.
01. Introduction to Android Prof. Oum Saokosal Master of Engineering in Information Systems, South Korea
DAY 14: ACCESS CHAPTER 1 Tazin Afrin October 03,
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 5: Investigate! Android Lists, Arrays,
ADO.NET A2 Teacher Up skilling LECTURE 3. What’s to come today? ADO.NET What is ADO.NET? ADO.NET Objects SqlConnection SqlCommand SqlDataReader DataSet.
ANDROID Presented By Mastan Vali.SK. © artesis 2008 | 2 1. Introduction 2. Platform 3. Software development 4. Advantages Main topics.
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.
COMP 365 Android Development.  Manages access from a central database  Allows multiple applications to access the same data.
This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit
DUE Hello World on the Android Platform.
CS378 - Mobile Computing Intents.
16 Services and Broadcast Receivers CSNB544 Mobile Application Development Thanks to Utexas Austin.
LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,
1 Data Bound Controls II Chapter Objectives You will be able to Use a Data Source control to get data from a SQL database and make it available.
CS378 - Mobile Computing Intents. Allow us to use applications and components that are part of Android System – start activities – start services – deliver.
Oracle Data Integrator Procedures, Advanced Workflows.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 5 Arrays.
Database Design and Management CPTG /23/2015Chapter 12 of 38 Functions of a Database Store data Store data School: student records, class schedules,
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
Copyright © 2006 Pilothouse Consulting Inc. All rights reserved. Search Overview Search Features: WSS and Office Search Architecture Content Sources and.
Database Access Using JDBC BCIS 3680 Enterprise Programming.
Basics of JDBC Session 14.
CSE 486/586, Spring 2014 CSE 486/586 Distributed Systems Android Programming Steve Ko Computer Sciences and Engineering University at Buffalo.
+ Structured Query Language Part 2 KROENKE and AUER - DATABASE CONCEPTS (6th Edition) Copyright © 2013 Pearson Education, Inc. Publishing as Prentice Hall.
Computers Are Your Future Tenth Edition Spotlight 5: Microsoft Office Copyright © 2009 Pearson Education, Inc. Publishing as Prentice Hall1.
Mobile Software Development for Android - I397 IT COLLEGE, ANDRES KÄVER, WEB:
17 Copyright © 2006, Oracle. All rights reserved. Information Publisher.
By: Eliav Menachi.  On Android, all application data (including files) are private to that application  Android provides a standard way for an application.
 This work confers an application which makes possible to use a Bluetooth enabled mobile phone to remote control home appliances such electric fan, LEDs.
The Ingredients of Android Applications. A simple application in a process In a classical programming environment, the OS would load the program code.
Data Storage in Android Димитър Н. Димитров. Why talk about data? Why not 3D graphics or network connectivity? Data as fundamental term in computer science.
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.
Chapter 5: Investigate! Lists, Arrays, and Web Browsers.
Content Providers.
CS371m - Mobile Computing Intents 1. Allow us to use applications and components that are already part of Android System – start activities – start services.
ASP.NET Programming with C# and SQL Server First Edition
Content provider.
Android Content Providers & SQLite
Content Providers And Content Resolvers
Android.
CS499 – Mobile Application Development
Content Providers.
CMPE419 Mobile Application Development
Mobile Software Development for Android - I397
Emerging Platform#3 Android & Programming an App
CMPE419 Mobile Application Development
Mobile Programming Dr. Mohsin Ali Memon.
Presentation transcript:

CS378 - Mobile Computing Content Providers And Content Resolvers

Content Providers One of the four primary application components: – activities – content providers – 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

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 set of data encapsulate the data and provide mechanisms for defining data security 4

Content Provider - Content Resolver 5 Calendar App Data Call Log Data Your App Content Provider Content Resolver data

Content Providers Many of the built in applications have content providers to allow other apps to access data Examples of built in content providers – AlarmClock – CalendarContract (API level 14) – CallLog (sent and received calls) – ContactsContract – MediaStore (audio / visual data) – UserDictionary – Voic Contract – many, many more 6

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 7

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

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 9

Accessing Content via Provider Example: Exploring Images on a device MediaStore.Images.Media class is one of the ContentProviders get the cursor: 10

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, 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 11

Accessing Content via Provider After obtaining cursor: result: 12

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] 13

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

MediaStore.Images.Media Columns 15

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

Showing Data in Logcat 17

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 18

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

Using Selection Criteria Example gets rows in table the selection criteria and selection args allow picking only certain rows essentially an SQL WHERE clause – specify a criteria that must be met ? is value filled in with selectionArgs – multiple criteria possible, AND, OR, NOT 20

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 21

Result 22

Why selectionCriteria and selectionArgs?? Why not just say: – selectionCriteria = "MediaStore.Images.Media.SIZE > " 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 *;" 23

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 24

Display Data from ContentProvider 25

Display Data from ContentProvider rest of populateListView from ListActivity 26

Subclass Adapter 27

Results 28

Permissions Using certain content providers require an application request permission – so user aware what content the application will access and possibly modify 29

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 30

ContentProviders and Intents Some Content Providers have such 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 31

Calendar Event Add 32

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 33

LOADERS 34

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 35

CursorLoader create a loader – API level 11 or greater – 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 onCreateLoader(int id, Bundle args) – public void onLoadFinished(Loader loader, Cursor data) – public void onLoaderReset(Loader loader) 36

Creating ContentProvider It is possible to implement a ContentProvider for your app 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. Not normally necessary until you create that million download app 37

CONTRACTS 38

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 39

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

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

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 42

Bonus - Oracle v. Google 43

Summary and Timeline Oracle is suing Google for its use of Java in the Android operating system brief timeline from pc worldpc world August Google buys Android Inc. Soon after, it discusses the possibility of licensing Java from Sun. October Andy Rubin, the head of Google's Android division, writes in an that Google can either adopt Microsoft's C# for Android or "do Java anyway and defend our decision, perhaps making enemies along the way." Over the next several months, Google and Sun continue to negotiate for a Java license but fail to reach a deal. February Sun supposedly offers Google a three-year Java license for US$20 million plus 10 percent of Google's Android-related revenue, capped at $25 million. Google rejects the offer. 44

TimeLine Continued November Google announces publicly that it is developing Android, which includes a Java-compatible virtual machine called Dalvik. October HTC releases the first Android phone, the HTC Dream. January Oracle acquires Sun and inherits its Java patents and copyrights. July Oracle meets with Google's lawyers to discuss Oracle's patent infringement allegations. Aug. 6, Rubin receives an from a Google engineer stating that the alternatives to Java "all suck" and that "we need to negotiate a license for Java under the terms we need." Aug. 12, Oracle files a lawsuit against Google, accusing it of infringing seven Java patents and its Java copyrights. Google denies any wrongdoing and calls the lawsuit a "baseless attack" on Google and open-source developers. 45

Timeline Continued January Android accounts for one-third of all smartphone sales, Canalys says. February Google asks the U.S. Patent and Trademark Office to reexamine Oracle's patents, arguing they shouldn't have been issued. By the time the trial starts, only two of the seven patents remain in the suit. June A court filing reveals that Oracle is seeking between $1.4 billion and $6.1 billion in damages. July A judge rules that Oracle "overreached" with its damages estimate and tells it to recalculate. 46

Timeline Continued September The CEOs of Oracle and Google, Larry Ellison and Larry Page, are ordered to hold settlement talks but can't reach agreement. November Android accounts for more than 50 percent of smartphone sales, Gartner says. March The two sides are ordered to hold more settlement talks but still can't reach a deal. April An eight-week jury trial is scheduled to begin Monday, April 16, at the U.S. District Court in San Francisco. 47

Some of Oracle's Evidence 48

Court Briefs 49

RangeCheck method java.util.Arrays, Google Android Code 50

Court Briefs The Introduction and Overview portions are good summaries of the positions read over the summaries provided June 1, 2012 case was dismissed Judge ruled APIs cannot be copyrighted 9 lines of copied code – no violation, dismissed – rangeCheck method simple code 51