CS499 – Mobile Application Development

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.
@2011 Mihail L. Sichitiu1 Android Introduction Hello Views Part 1.
Cosc 4730 Android TabActivity and ListView. TabActivity A TabActivity allows for multiple “tabs”. – Each Tab is it’s own activity and the “root” activity.
CS378 - Mobile Computing Persistence - SQLite. Databases RDBMS – relational data base management system Relational databases introduced by E. F. Codd.
Presenting Lists of Data. Lists of Data Issues involved – unknown number of elements – allowing the user to scroll Data sources – most common ArrayList.
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.
Data Storage: Part 3 (SQLite)
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Content Providers & Services.
ANDROID CONTENT PROVIDERS Peter Liu School of ICT, Seneca College.
Chapter 2: Simplify! The Android User Interface
Android Activities 1. What are Android Activities? Activities are like windows in an Android application An application can have any number of activities.
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.
Rajab Davudov. Agenda Eclipse, ADT and Android SDK APK file Fundamentals – Activity – Service – Content Provider – Broadcast Receiver – Intent Hello World.
CSE 486/586, Spring 2012 CSE 486/586 Distributed Systems Recitation.
Chapter 2 The Android User Interface. Objectives  In this chapter, you learn to:  Develop a user interface using the TextView, ImageView, and Button.
Android Content Providers In Android security model, one application cannot directly access (read/write) other application's data. Every application has.
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.
Mobile Software Development ISCG 7424 Department of Computing UNITEC John Casey and Richard Rabeder SQLite and Permissions.
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.
Android Alert Dialog. Alert Dialog Place Button to open the dialog. public class MainActivity extends ActionBarActivity { private static Button button_sbm;
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.
Mobile Programming Lecture 4 Resources, Selection, Activities, Intents.
Mobile Software Development for Android - I397 IT COLLEGE, ANDRES KÄVER, WEB:
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
The Ingredients of Android Applications. A simple application in a process In a classical programming environment, the OS would load the program code.
Content Providers.
CS499 – Mobile Application Development
Making content providers
Chapter 2: Simplify! The Android User Interface
Android Application -Architecture.
Content provider.
Android Content Providers & SQLite
Data Storage: Part 4 (Content Providers)
Mobile Software Development for Android - I397
Content Providers And Content Resolvers
CS499 – Mobile Application Development
SQLite in Android Landon Cox March 2, 2017.
ListView: Part 2.
Android Application SQLite 1.
Reactive Android Development
Content Providers.
Mobile Software Development for Android - I397
Mobile Computing With Android ACST Android Database Storage Part 2
CMPE419 Mobile Application Development
CS371m - Mobile Computing Persistence - SQLite.
CS323 Android Topics Network Basics for an Android App
Mobile Computing With Android ACST 4550 Android Database Storage
plus content providers, loaders, recyclerview
Mobile Programming Dr. Mohsin Ali Memon.
Presentation transcript:

CS499 – Mobile Application Development Fall 2013 Programming the Android Platform Content Providers

Content Providers Datastore and interface to contents, allowing information to be shared (queried, updated, added, deleted) across apps. Datastore is pointed at via a URI (Uniform Resource Identifier) The data type for each column in a provider is usually listed in its documentation. Use Cursor objects to process the data. Ex: Contact list, Settings, CallLog, UserWordDictionary … – all provided with Android

Other Standard Content Providers  UserDictionary.Words.CONTENT_URI (content://user_dictionary/words)

Using Content Providers: Contacts Contact list set up to be available to any other app by using the correct URI (path) and methods. Complex data access via a Cursor Need to declare android.permission.READ_CONTACTS and android.permission.WRITE_CONTACTS in the manifest

Querying Use query() to retrieve data Returns a Cursor instance for accessing results A Cursor is an iterator over a result set Cursor query( Uri uri, // ContentProvider URI String[] projection // Columns to retrieve String selection // SQL selection pattern String[] selectionArgs // SQL pattern args String sortOrder // Sort order )

Cursor Provides access to query results SimpleCursorAdapter – can be used with ListView Some useful methods: boolean moveToFirst() boolean moveToNext() int getColumnIndex(String columnName) String getString(int columnIndex)

Contact List - 1

ContactList1 – on blackboard public class ContactsEditActivity extends ListActivity { private Cursor mContacts; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Return all contacts ordered by name String[] projection = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME }; // Get all contacts visible to the user mContacts = managedQuery(ContactsContract.Contacts.CONTENT_URI, projection, null, null, ContactsContract.Contacts.DISPLAY_NAME); // Display contacts in a ListView SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, mContacts, new String[] {ContactsContract.Contacts.DISPLAY_NAME }, new int[] {android.R.id.text1}); setListAdapter(mAdapter); } ContactList1 – on blackboard

Contract Classes ContactsContract.Contacts.DISPLAY_NAME A contract class defines constants that help applications work with the content URIs, column names, intent actions, and other features of a content provider. Contract classes are not included automatically with a provider; the provider's developer has to define them and then make them available to other developers.

Contact List 2 Listener queries for email and phone info Creates an AlertDialog

public void onItemClick(AdapterView< public void onItemClick(AdapterView<?> parent, View v, int position, long id) { if (mContacts.moveToPosition(position)) { int selectedId = mContacts.getInt(0); // _ID Column // gather email data from the tables Cursor email = getContentResolver().query( CommonDataKinds.Email.CONTENT_URI, new String[] {CommonDataKinds.Email.DATA }, ContactsContract.Data.CONTACT_ID + " = " + selectedId, null, null); Cursor phone = getContentResolver().query( CommonDataKinds.Phone.CONTENT_URI, new String[] {CommonDataKinds.Phone.NUMBER }, // Build the Dialog message StringBuilder sb = new StringBuilder(); sb.append(email.getCount() + " Emails\n"); if (email.moveToFirst()) { do { sb.append("Email: " + email.getString(0)); sb.append('\n'); } while (email.moveToNext()); sb.append('\n'); } sb.append(phone.getCount() + " Phone Numbers\n"); if (phone.moveToFirst()) { do { sb.append("Phone: " + phone.getString(0)); sb.append('\n'); } while (phone.moveToNext()); } // Create the Dialog AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(mContacts.getString(1)); // Display name builder.setMessage(sb.toString()); builder.setPositiveButton("OK", null); builder.create().show(); email.close(); phone.close();

Deleting Use delete() to delete data private void deleteContact(String name) { getContentResolver().delete( ContactsContract.RawContacts.CONTENT_URI, ContactsContract.Contacts.DISPLAY_NAME+”=?”, new String[] {name}); } private void deleteAllContacts() { null,null);

Add/Update Starting to move into db topics (next week)…

Creating Content Providers You need to create a content provider if: Your app needs to offer complex data or files to other apps You want to allow users to copy complex data from your app to other apps Allows you to offer both file and “structured” data to other apps. You do not need a content provider to have a SQL database inside a particular app.

ContentProvider class Six abstract methods query() - Retrieve data from your provider. insert() - Insert a new row into your provider. update() - Update existing rows in your provider. delete() - Delete rows from your provider. getType() - Return the MIME type corresponding to a content URI. onCreate() Initialize your provider. These methods (except onCreate() ) may be called from multiple apps so must be thread-safe. Use permissions in manifest to control what apps can access your data

URLS http://developer.android.com/guide/topics/providers/content-providers.html http://developer.android.com/guide/topics/providers/contacts-provider.html