Mobile Programming Lecture 10. ContentProviders

Size: px
Start display at page:

Download "Mobile Programming Lecture 10. ContentProviders"

Transcription

1 Mobile Programming Lecture 10 ContentProviders

2 Lecture 9 Review In creating a bound service, why would you choose to use a Messenger over extending Binder? What are the differences between using GPS provider and Network provider? When should you stop listening for location updates? Why at that point? How would you implement turn-by-turn directions? When should you disable a Sensor?

3 Lecture 9 Review How do you start an Activity B from and Activity A, and get a result back from Activity B when B has completed? How can you find out the structure of the intent filter for a given intent in the system?

4 Agenda ContentProviders Querying existing databases Creating a database for your app Inserting data Updating data Deleting data Content provider permissions Viewing ContentProvider data

5 Android Application Components 1. Activity 2. Broadcast Receiver 3. Content Provider 4. Service

6 Content Provider Basics A Content Provider manages access to a central repository of data Content providers are primarily intended to be used by other applications, which access the provider using a provider client object A Content Provider presents data to external applications as one or more tables that are similar to the tables found in a relational database

7 Content Provider Basics When you want to access data in a Content Provider, you use the ContentResolver object in your application's Context to communicate with the provider as a client The ContentResolver object communicates with the provider object, an instance of a class that implements ContentProvider The provider object receives data requests from clients, performs the requested action, and returns the results.

8 Content Provider Basics You don't need to develop your own provider if you don't intend to share your data with other applications, instead Use SharedPreferences The reason you use a ContentProvider is Data is too complex for SharedPreferences Expose your data to other applications

9 Content Provider Basics _ID column serves as the primary key column that the Content Provider automatically maintains Here's an example of a table with an _ID column word app id frequency locale _ID mapreduce user1 100 en_us 1 precompiler user fr_fr 2 applet user2 225 fr_ca 3 const user1 255 pt_br 4 int user5 100 en_uk 5

10 Contacts ContentProvider In our examples, we will look at the Contacts ContentProvider A lot of the work for a query goes into reading the documentation online

11 Requesting Permission In order to read the user's contacts, you need to request permission first android.permission.read_contacts

12 Constructing a Query Let's build several queries for ContractsContract.Contacts The columns can be found in the documentation here A few of the columns are... _ID LOOKUP_KEY NAME_RAW_CONTACT_ID DISPLAY_NAME_PRIMARY PHOTO_ID PHOTO_URI IN_VISIBLE_GROUP HAS_PHONE_NUMBER TIMES_CONTACTED long String long String long long int int int

13 Constructing a Query We will use the following fields in our class in our examples public class ContactsContractExampleActivity extends ListActivity { Cursor mcursor; CursorAdapter mcursoradapter; String[] mprojection; String[] mlistcolumns; String mselectionclause; String[] mselectionargs; String morderby; public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate);

14 Constructing a Query We will use the following fields in our class in our examples public class ContactsContractExampleActivity extends ListActivity { Cursor mcursor; CursorAdapter mcursoradapter; String[] mprojection; String[] mlistcolumns; String mselectionclause; String[] mselectionargs; String morderby; Note that we're extending ListActivity, so we don't need to add a ListView to our XML layout file. We don't even need an XML layout file public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate);

15 Constructing a Query Consider the following SQL queries

16 Constructing a Query - Query 1 SELECT * FROM ContactsContract.Contacts "Get every column for every contact in this database table"

17 Constructing a Query - Query 1 public void oncreate(bundle savedinstancestate) { mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, null, null, null, null); mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems); setlistadapter(mcursoradapter);

18 Constructing a Query - Query 1 public void oncreate(bundle savedinstancestate) { mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, null, null, null, null); When you want to access data in a content provider, you need to use a ContentResolver. You can get the ContentResolver by calling getcontentresolver() mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems); setlistadapter(mcursoradapter);

19 Constructing a Query - Query 1 public void oncreate(bundle savedinstancestate) { mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, null, null, null, It returns a Cursor null); object. mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems); setlistadapter(mcursoradapter);

20 Constructing a Query - Query 1 public void oncreate(bundle savedinstancestate) { mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, null, null, null, null); mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems); Using a Cursor object, you can call the query() method to execute a query on a content provider. setlistadapter(mcursoradapter);

21 Constructing a Query - Query 1 public void oncreate(bundle savedinstancestate) { mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, null, null, null, null); mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME Passing null means return all columns, ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems); The second argument is a String array (i.e. String[ ]) of which columns we want to be returned by the query. i.e. SELECT * setlistadapter(mcursoradapter);

22 Constructing a Query - Query 1 public void oncreate(bundle savedinstancestate) { mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, null, null, null, null); The first argument to Cursor.query() is a Uri. It specifies the table that you want to access, i.e. SELECT * FROM table mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems); setlistadapter(mcursoradapter);

23 Constructing a Query - Query 1 public void oncreate(bundle savedinstancestate) { mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, null, null, null, null); ContactsContract is a content provider. You can think of it as the database mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems); setlistadapter(mcursoradapter);

24 Constructing a Query - Query 1 public void oncreate(bundle savedinstancestate) { mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, null, null, null, null); ContactsContract.Contacts is a content provider. You can think of it as a table in the database mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems); setlistadapter(mcursoradapter);

25 Constructing a Query - Query 1 public void oncreate(bundle savedinstancestate) { mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, null, null, null, null); mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems); This is one of the Uris for the table, which says how you want to access the table. Some tables have multiple Uris setlistadapter(mcursoradapter);

26 Constructing a Query - Query 1 public void oncreate(bundle savedinstancestate) { mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, null, null, null, null); mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME query. Passing null means don't ; mlistitems = new int[] { R.id.contact_name ; The third argument is a String. Here you specify the conditions for your specify any conditions mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems); setlistadapter(mcursoradapter);

27 Constructing a Query - Query 1 public void oncreate(bundle savedinstancestate) { mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, null, null, null, null); mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems); The fourth argument is a String[ ]. We will get back to this soon setlistadapter(mcursoradapter);

28 Constructing a Query - Query 1 public void oncreate(bundle savedinstancestate) { mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, null, null, null, null); The fifth argument is a String. It says how we want to sort our results. Passing null means don't specify any sorting mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems); setlistadapter(mcursoradapter);

29 Constructing a Query - Query 1 public void oncreate(bundle savedinstancestate) { mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, null, null, null, null); SELECT * FROM ContactsContract.Contacts mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems); setlistadapter(mcursoradapter);

30 Constructing a Query - Query 1 public void oncreate(bundle savedinstancestate) { mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, null, null, null, null); mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; Our query is now complete, and the Cursor can iterate through the results. But since we want to attach our results to a ListView, we need to add a few more lines of code mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems); setlistadapter(mcursoradapter);

31 Constructing a Query - Query 1 public void oncreate(bundle savedinstancestate) { mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, null, null, null, null); mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; Although our query was on all columns, here we create a String array of the columns we want to have displayed in our ListView. mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems); setlistadapter(mcursoradapter);

32 Constructing a Query - Query 1 public void oncreate(bundle savedinstancestate) { mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, null, null, null, null); mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems); The column names are usually constants that you can reference via the database table setlistadapter(mcursoradapter);

33 Constructing a Query - Query 1 In order to setup our ListView properly, we need to create an XML layout file that can represent each row in the list. We create a Layout XML file called query1.xml, which has the following TextView

34 Constructing a Query - Query 1 <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android=" android:id="@+id/contact_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="large Text" android:textappearance="?android:attr/textappearancelarge" />

35 Constructing a Query - Query 1 <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android=" android:id="@+id/contact_name" android:layout_width="wrap_content" Note the android:id attribute of the TextView android:layout_height="wrap_content" android:text="large Text" android:textappearance="?android:attr/textappearancelarge"/>

36 Constructing a Query - Query 1 public void oncreate(bundle savedinstancestate) { mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, null, null, null, null); mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems); setlistadapter(mcursoradapter);

37 Constructing a Query - Query 1 public void oncreate(bundle savedinstancestate) { mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, null, null, null, null); mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems); So, String[ ] mlistcolumns specifies which columns we want to select setlistadapter(mcursoradapter);

38 Constructing a Query - Query 1 public void oncreate(bundle savedinstancestate) { mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, null, null, null, null); mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems); and int[] mlistitems is a corresponding array, telling us where to place the actual value of the DISPLAY_NAME setlistadapter(mcursoradapter);

39 Constructing a Query - Query 1 public void oncreate(bundle savedinstancestate) { mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, null, null, null, null); mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems); It will be placed in this TextView, whose android:id="@+id/contact_name" setlistadapter(mcursoradapter);

40 Constructing a Query - Query 1 public void oncreate(bundle savedinstancestate) { mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, null, null, null, null); mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems); setlistadapter(mcursoradapter); We've been using ArrayAdapters with ListViews in the past, but here we use a SimpleCursorAdapter instead, because we have a Cursor (i.e. mcursor)

41 Constructing a Query - Query 1 public void oncreate(bundle savedinstancestate) { mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, null, null, null, null); mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems); First argument is a Context setlistadapter(mcursoradapter);

42 Constructing a Query - Query 1 public void oncreate(bundle savedinstancestate) { mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, null, null, null, null); mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems); Second argument is our Layout XML file resource used to construct the ListView setlistadapter(mcursoradapter);

43 Constructing a Query - Query 1 public void oncreate(bundle savedinstancestate) { mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, null, null, null, null); mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems); setlistadapter(mcursoradapter); Third argument is our Cursor object

44 Constructing a Query - Query 1 public void oncreate(bundle savedinstancestate) { mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, null, null, null, null); mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems); setlistadapter(mcursoradapter); Fourth argument is our String array of column names

45 Constructing a Query - Query 1 public void oncreate(bundle savedinstancestate) { mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, null, null, null, null); mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems); setlistadapter(mcursoradapter); Fifth argument our int array of TextView resources

46 Constructing a Query - Query 1 public void oncreate(bundle savedinstancestate) { mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, null, null, null, null); mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, Finally, we call setlistadapter and mlistitems); pass our SimpleCursorAdapter setlistadapter(mcursoradapter);

47 Constructing a Query - Query 1 See the query1() method inside of ContactsContractQueryExample.tar This query is inefficient, because we're requesting all columns, but yet only using one column after we get the results

48 Constructing a Query - Query 2 Consider the following SQL query SELECT _ID, DISPLAY_NAME FROM ContactsContract.Contacts "Get the _ID and DISPLAY_NAME for all contacts"

49 Constructing a Query - Query 2 public void oncreate(bundle savedinstancestate) { mprojection = new String[] { ContactsContract.Contacts. _ID, ContactsContract.Contacts. DISPLAY_NAME ; mcursor = getcontentresolver().query( ContactsContract.Contacts. CONTENT_URI, mprojection, null, null, null); mlistcolumns = new String[] { ContactsContract.Contacts. DISPLAY_NAME ; mlistitems = new int[] { R.id. contact_name ; mcursoradapter = new SimpleCursorAdapter( this, R.layout.query1, mcursor, mlistcolumns, mlistitems);

50 Constructing a Query - Query 2 public void oncreate(bundle savedinstancestate) { mprojection = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME ; mcursor = getcontentresolver().query( Here we make a String array ContactsContract.Contacts.CONTENT_URI, of the columns that we need. mprojection, null, null, null); mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems);

51 Constructing a Query - Query 2 public void oncreate(bundle savedinstancestate) { mprojection = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME ; mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, mprojection, null, null, null); Instead of passing null, we pass our String array of mlistcolumns = new String[] { column names ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems);

52 Constructing a Query - Query 2 public void oncreate(bundle savedinstancestate) { mprojection = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME ; mcursor = getcontentresolver(). query( ContactsContract.Contacts.CONTENT_URI, mprojection, null, null, null); mlistcolumns = new String[] SELECT { _ID, DISPLAY_NAME FROM ContactsContract.Contacts ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems);

53 Constructing a Query - Query 2 public void oncreate(bundle savedinstancestate) { mprojection = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME ; mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, mprojection, null, null, This hasn't changed null); mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems);

54 Constructing a Query - Query 2 See the query2() method inside of ContactsContractQueryExample.tar

55 Constructing a Query - Query 3 Consider the following SQL query SELECT _ID, DISPLAY_NAME FROM ContactsContract.Contacts WHERE HAS_PHONE_NUMBER = 1 "Get the _ID and DISPLAY_NAME for all contacts that have phone numbers"

56 Constructing a Query - Query 3 public void oncreate(bundle savedinstancestate) { mprojection = new String[] { ContactsContract.Contacts. _ID, ContactsContract.Contacts. DISPLAY_NAME ; mselectionclause = ContactsContract.Contacts. HAS_PHONE_NUMBER + " =?"; mselectionargs = new String[]{ "1"; mcursor = getcontentresolver().query( ContactsContract.Contacts. CONTENT_URI, mprojection, null, null, null); mlistcolumns = new String[] { ContactsContract.Contacts. DISPLAY_NAME ; mlistitems = new int[] { R.id. contact_name ; mcursoradapter = new SimpleCursorAdapter( this, R.layout.query1, mcursor, mlistcolumns, mlistitems);

57 Constructing a Query - Query 3 mprojection has not changed public void oncreate(bundle savedinstancestate) { mprojection = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME ; mselectionclause = ContactsContract.Contacts.DISPLAY_NAME + " =? "; mselectionargs = new String[]{"Fred"; mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, mprojection, null, null, null); mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems);

58 Constructing a Query - Query 3 public void oncreate(bundle savedinstancestate) { Here we use "?" as a placeholder. ContactsContract.Contacts.HAS_PHONE_NUMBER mprojection = new String[] { ContactsContract.Contacts._ID, is a String, so we're appending ContactsContract.Contacts.DISPLAY_NAME " =?" to this String0 ; mselectionclause = ContactsContract.Contacts.HAS_PHONE_NUMBER + " =? "; mselectionargs = new String[]{"1"; mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, mprojection, null, null, null); mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems);

59 Constructing a Query - Query 3 public void oncreate(bundle savedinstancestate) { mprojection = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME ; mselectionclause = ContactsContract.Contacts.HAS_PHONE_NUMBER + " =? "; mselectionargs = new String[]{"1"; Each "?" will be replaced by an element mcursor = getcontentresolver().query( in this String array, sequentially. In this case we only have one "?" ContactsContract.Contacts.CONTENT_URI, mprojection, null, null, null); mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems);

60 Constructing a Query - Query 3 public void oncreate(bundle savedinstancestate) { mprojection = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME ; mselectionclause = ContactsContract.Contacts.HAS_PHONE_NUMBER + " =? "; mselectionargs = new String[]{"1"; mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, mprojection, mselectionclause, mselectionargs, null); mlistcolumns = new String[] { Now instead of passing null for the ContactsContract.Contacts.DISPLAY_NAME selection clause, we pass our ; mlistitems = new int[] { R.id.contact_name mselectionclause ; String mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems);

61 Constructing a Query - Query 3 public void oncreate(bundle savedinstancestate) { mprojection = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME ; mselectionclause = ContactsContract.Contacts.HAS_PHONE_NUMBER + " =? "; mselectionargs = new String[]{"1"; mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, mprojection, mselectionclause, mselectionargs, null); mlistcolumns = new String[] { Instead of passing null, we pass our ContactsContract.Contacts.DISPLAY_NAME ; selection args array mselectionargs mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems);

62 Constructing a Query - Query 3 public void oncreate(bundle savedinstancestate) { mprojection = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME ; mselectionclause = ContactsContract.Contacts.HAS_PHONE_NUMBER + " =? "; mselectionargs = new String[]{"1"; mcursor = getcontentresolver(). query( ContactsContract.Contacts.CONTENT_URI, mprojection, mselectionclause, mselectionargs, null); SELECT _ID, DISPLAY_NAME mlistcolumns = new String[] { FROM ContactsContract.Contacts WHERE ContactsContract.Contacts.DISPLAY_NAME HAS_PHONE_NUMBER = 1 ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems);

63 Constructing a Query - Query 3 public void The? is oncreate(bundle a placeholder here, savedinstancestate) just { mprojection as %d or %s = is new a placeholder String[] { ContactsContract.Contacts._ID, when you call printf() ContactsContract.Contacts.DISPLAY_NAME ; mselectionclause = ContactsContract.Contacts.HAS_PHONE_NUMBER + " =? "; mselectionargs = new String[]{"1"; mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, mprojection, null, null, null); mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems);

64 Constructing a Query - Query 3 See the query3() method inside of ContactsContractQueryExample.tar

65 Constructing a Query - Query 4 Consider the following SQL query SELECT _ID, DISPLAY_NAME, TIMES_CONTACTED FROM ContactsContract.Contacts WHERE HAS_PHONE_NUMBER = 1 AND TIMES_CONTACTED > 5 "Get the _ID and DISPLAY_NAME for all contacts that have a phone number and that I've contacted more than 5 times"

66 Constructing a Query - Query 4 public void oncreate(bundle savedinstancestate) { mprojection = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME ; mselectionclause = ContactsContract.Contacts.HAS_PHONE_NUMBER + " =? AND " + ContactsContract.Contacts.TIMES_CONTACTED + " >? "; mselectionargs = new String[]{ "1", "5" ; mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, mprojection, mselectionclause, mselectionargs, null); mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems);

67 Constructing a Query - Query 4 We modify our selection clause slightly, to also have the condition public that void the oncreate(bundle contact must have savedinstancestate) been { mprojection contacted more = new than String[] 5 times { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME ; mselectionclause = ContactsContract.Contacts.HAS_PHONE_NUMBER + " =? AND " + ContactsContract.Contacts.TIMES_CONTACTED + " >? "; mselectionargs = new String[]{"1", "5"; mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, mprojection, mselectionclause, mselectionargs, null); mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems);

68 Constructing a Query - Query 4 public void oncreate(bundle savedinstancestate) { mprojection = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME ; mselectionclause = ContactsContract.Contacts.HAS_PHONE_NUMBER + " =? AND " + Since we have a new condition, ContactsContract.Contacts.TIMES_CONTACTED + " >? "; we also add the argument to the mselectionargs = new String[]{"1", "5"; condition to our selection mcursor = getcontentresolver().query( arguments String array ContactsContract.Contacts.CONTENT_URI, mprojection, mselectionclause, mselectionargs, null); mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems);

69 Constructing a Query - Query 4 public void oncreate(bundle savedinstancestate) { mprojection = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME ; mselectionclause = ContactsContract.Contacts.HAS_PHONE_NUMBER + " =? AND " + ContactsContract.Contacts.TIMES_CONTACTED + " >? "; mselectionargs = new String[]{"1", "5"; mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, mprojection, mselectionclause, mselectionargs, null); SELECT _ID, DISPLAY_NAME, TIMES_CONTACTED mlistcolumns = new String[] { FROM ContactsContract.Contacts WHERE HAS_PHONE_NUMBER ContactsContract.Contacts.DISPLAY_NAME = 1 ; mlistitems = AND new int[] TIMES_CONTACTED { R.id.contact_name > 5 ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems);

70 Constructing a Query - Query 4 public void oncreate(bundle savedinstancestate) { mprojection = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME ; mselectionclause = ContactsContract.Contacts.HAS_PHONE_NUMBER + " =? AND " + ContactsContract.Contacts.TIMES_CONTACTED The rest hasn't + " >? "; mselectionargs = new String[]{"1", "5"; changed mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, mprojection, mselectionclause, mselectionargs, null); mlistcolumns = new String[] { ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems);

71 Constructing a Query - Query 4 See the query4() method inside of ContactsContractQueryExample.tar

72 Constructing a Query - Query 5 Consider the following SQL query SELECT _ID, DISPLAY_NAME FROM ContactsContract.Contacts WHERE HAS_PHONE_NUMBER = 1 ORDER BY DISPLAY_NAME "Get the _ID and DISPLAY_NAME for all contacts that have phone numbers, and sort the results by DISPLAY_NAME"

73 Constructing a Query - Query 5 FYI, we will build this query off of query3, not query4

74 Constructing a Query - Query 5 public void oncreate(bundle savedinstancestate) { mprojection = new String[] { ContactsContract.Contacts. _ID, ContactsContract.Contacts. DISPLAY_NAME ; mselectionclause = ContactsContract.Contacts. HAS_PHONE_NUMBER + " =? "; mselectionargs = new String[]{ "1" ; morderby = ContactsContract.Contacts. DISPLAY_NAME; mcursor = getcontentresolver().query( ContactsContract.Contacts. CONTENT_URI, mprojection, mselectionclause, mselectionargs, morderby); mlistcolumns = new String[] { ContactsContract.Contacts. DISPLAY_NAME ; mlistitems = new int[] { R.id. contact_name ; mcursoradapter = new SimpleCursorAdapter( this, R.layout.query1, mcursor, mlistcolumns, mlistitems);

75 Constructing a Query - Query 5 public void oncreate(bundle savedinstancestate) { mprojection = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME ; mselectionclause = ContactsContract.Contacts.HAS_PHONE_NUMBER Here we have + a String specifying the column by " =? "; which we want to sort. In this mselectionargs = new String[]{"1"; case, the DISPLAY_NAME morderby = ContactsContract.Contacts.DISPLAY_NAME; mcursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, mprojection, mlistcolumns = new String[] { mselectionclause, mselectionargs, morderby); ContactsContract.Contacts.DISPLAY_NAME ; mlistitems = new int[] { R.id.contact_name ; mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems);

76 Constructing a Query - Query 5 public void oncreate(bundle savedinstancestate) { mprojection = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME ; mselectionclause = ContactsContract.Contacts.HAS_PHONE_NUMBER + " =? "; mselectionargs = new String[]{"1"; morderby = ContactsContract.Contacts.DISPLAY_NAME; mcursor = getcontentresolver(). query( ContactsContract.Contacts.CONTENT_URI, mprojection, mselectionclause, mselectionargs, morderby); mlistcolumns SELECT = new _ID, String[] DISPLAY_NAME { FROM ContactsContract.Contacts ContactsContract.Contacts.DISPLAY_NAME ; WHERE HAS_PHONE_NUMBER = 1 mlistitems = new int[] { R.id.contact_name ; ORDER BY DISPLAY_NAME mcursoradapter = new SimpleCursorAdapter(this, R.layout.query1, mcursor, mlistcolumns, mlistitems);

77 Constructing a Query - Query 5 See the query5() method inside of ContactsContractQueryExample.tar

78 Iterating through query results You may not always want to add the results from a query to a ListView. Sometimes you just need to go through the results one-by-one

79 Iterating through query results Cursor cursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, projection, selectionclause, selectionargs, null); if (cursor!= null) { while (cursor.movetonext()) { cursor.getstring(1);

80 Iterating through query results Cursor cursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, projection, selectionclause, selectionargs, null); if(cursor!= null) { while(cursor.movetonext()) { cursor.getstring(1); After executing the query...

81 Iterating through query results Cursor cursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, projection, selectionclause, selectionargs, null); if(cursor!= null) { while(cursor.movetonext()) { cursor.getstring(1); Make sure that the Cursor is not null before using it

82 Iterating through query results Cursor cursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, projection, selectionclause, selectionargs, null); if(cursor!= null) { while(cursor.movetonext()) { cursor.getstring(1); This returns true as long as there are more results to be fetched

83 Iterating through query results Cursor cursor = getcontentresolver().query( ContactsContract.Contacts.CONTENT_URI, projection, selectionclause, selectionargs, null); if(cursor!= null) { while(cursor.movetonext()) { cursor.getstring(1); Get the String represention of column number 1 (or use another integer if you want a different column value)

84 Iterating through query results See ContentProviderExample.tar

85 Creating a Content Provider There are two ways to store your data using a Content Provider 1. File data photos, audio, video, etc 2. Structured data data fit for a database We will look at structured data using SQLite databases

86 Creating a Content Provider Because writing to databases is a sensitive operation, in the next examples we will perform operations on our own SQLite database

87 Creating a Content Provider The steps for creating an SQLite DB for your app is not what you're used to, because doing it right means that you also need to understand URIs

88 Creating a Content Provider You should add the content provider via the Android Studio menu Click File > New > Other > Content Provider Provide a name for the Content Provider Provide an Authorities URI This should be your package name followed by.provider Click Finish

89 Creating a Content Provider Decide on the name of your database now, and we will add it as a field to the ContentProvider public class MyProvider extends ContentProvider { public final static String DBNAME = "NameDatabase";...

90 Creating a Content Provider Next we need to add a String containing the SQL query for creating the necessary tables for our database In our example, we will create a table in our database with the following structure Column Name _ID FirstName LastName Type Integer PRIMARY KEY TEXT TEXT

91 Creating a Content Provider public class MyProvider extends ContentProvider { public final static String DBNAME = "NameDatabase"; private static final String SQL_CREATE_MAIN = "CREATE TABLE Users ( " + " _ID INTEGER PRIMARY KEY, " + "FirstName TEXT, " + "LastName TEXT )";... If you're unfamiliar with SQL, see this page

92 Creating a Content Provider We will also add the CONTENT_URI Uri as a convenient way to get the URI for our database. We make it final because we don't want it to be modified after it has been set

93 Creating a Content Provider public class MyProvider extends ContentProvider { public final static String DBNAME = "NameDatabase"; private static final String SQL_CREATE_MAIN = "CREATE TABLE Users ( " + " _ID INTEGER PRIMARY KEY, " + "FirstName TEXT, " + "LastName TEXT )"; public static final Uri CONTENT_URI = Uri.parse("content://my.package.name.provider");...

94 Creating a Content Provider Before we implement any of the methods inside of your new ContentProvider, we need to add an inner class which extends SQLiteOpenHelper. This class will take care of Opening the database if it exists Creating it if it does not

95 Creating a Content Provider public class MyProvider extends ContentProvider {... protected static final class MainDatabaseHelper extends SQLiteOpenHelper { MainDatabaseHelper(Context context) { super(context, "NamesDatabase", null, 1); public void oncreate(sqlitedatabase db) { db.execsql(sql_create_main); public void onupgrade(sqlitedatabase arg0, int arg1, int arg2) {

96 Creating a Content Provider public class MyProvider extends ContentProvider {... The String we created previously protected static final class MainDatabaseHelper extends SQLiteOpenHelper { are here MainDatabaseHelper(Context context) { super(context, "NamesDatabase", null, 1); public void oncreate(sqlitedatabase db) { db.execsql(sql_create_main); public void onupgrade(sqlitedatabase arg0, int arg1, int arg2) {

97 Creating a Content Provider public class MyProvider extends ContentProvider {... protected static final class MainDatabaseHelper extends SQLiteOpenHelper { MainDatabaseHelper(Context context) { super(context, "NamesDatabase", null, 1); Make sure to call super, and pass the name of the database as the second argument public void oncreate(sqlitedatabase db) { db.execsql(sql_create_main); public void onupgrade(sqlitedatabase arg0, int arg1, int arg2) {

98 Creating a Content Provider public class MyProvider extends ContentProvider {... protected static final class MainDatabaseHelper extends SQLiteOpenHelper { MainDatabaseHelper(Context context) { super(context, "NamesDatabase", null, 1); public void oncreate(sqlitedatabase db) { The database will be created when db.execsql(sql_create_main); oncreate() is called on our inner class. Note that this oncreate() doesn't get called until you try to access the database public void onupgrade(sqlitedatabase arg0, int arg1, int arg2) {

99 Creating a Content Provider Now we can implement the methods for our ContentProvider

100 Implementing the oncreate() method public class MyContentProvider extends ContentProvider {... public boolean oncreate() { mopenhelper = new MainDatabaseHelper(getContext());... return true;

101 Implementing the oncreate() method public class MyContentProvider extends ContentProvider {... public boolean oncreate() { mopenhelper = new MainDatabaseHelper(getContext());... return true; We create an instance of our MainDatabaseHelper so that we can use it later for reading and modifying our NamesDatabase

102 Implementing the insert() method public class MyContentProvider extends ContentProvider {... public Uri insert(uri uri, ContentValues values) { String fname = values.getasstring("firstname"); String lname = values.getasstring("lastname"); long id = mopenhelper.getwritabledatabase().insert("users", null, values); return Uri.withAppendedPath(CONTENT_URI, "" + id);...

103 Implementing the insert() method public class MyContentProvider extends ContentProvider {... public Uri insert(uri uri, ContentValues values) { String fname = values.getasstring("firstname"); We must return a Uri. We will return a Uri that has the new id of the item that will be inserted in this method String lname = values.getasstring("lastname"); long id = mopenhelper.getwritabledatabase().insert("users", null, values); return Uri.withAppendedPath(CONTENT_URI, "" + id);...

104 Implementing the insert() method public class MyContentProvider extends ContentProvider {... public Uri insert(uri uri, ContentValues values) { String fname = values.getasstring("firstname"); This Uri can be used to identify the table in our database, but since we only have one table, we don't need to use it in this function String lname = values.getasstring("lastname"); long id = mopenhelper.getwritabledatabase().insert("users", null, values); return Uri.withAppendedPath(CONTENT_URI, "" + id);...

105 Implementing the insert() method public class MyContentProvider extends ContentProvider {... public Uri insert(uri uri, ContentValues values) { String fname = values.getasstring("firstname"); These are the values that will be String lname = values.getasstring("lastname"); inserted. They are key-value pairs long id = mopenhelper.getwritabledatabase().insert("users", null, values); return Uri.withAppendedPath(CONTENT_URI, "" + id);...

106 Implementing the insert() method public class MyContentProvider extends ContentProvider {... public Uri insert(uri uri, ContentValues values) { String fname = values.getasstring("firstname"); String lname = values.getasstring("lastname"); We get the FirstName and LastName values that were passed in long id = mopenhelper.getwritabledatabase().insert("users", null, values); return Uri.withAppendedPath(CONTENT_URI, "" + id);...

107 Implementing the insert() method public class MyContentProvider extends ContentProvider {... public Uri insert(uri uri, ContentValues values) { String fname = values.getasstring("firstname"); String lname = values.getasstring("lastname"); Before you call insert() and update(), you should check for invalid values and return null if there is any invalid input. We don't use fname and lname afterward, as we are just trying to illustrate how to use ContentValues long id = mopenhelper.getwritabledatabase().insert("users", null, values); return Uri.withAppendedPath(CONTENT_URI, "" + id);...

108 Implementing the insert() method public class MyContentProvider extends ContentProvider {... public Uri insert(uri uri, ContentValues values) { String fname = values.getasstring("firstname"); String lname = values.getasstring("lastname"); long id = mopenhelper.getwritabledatabase().insert("users", null, values); We need to call getwritabledatabase() to create and/or open our database which will be used for reading and writing return Uri.withAppendedPath(CONTENT_URI, "" + id);...

109 Implementing the insert() method public class MyContentProvider extends ContentProvider {... public Uri insert(uri uri, ContentValues values) { String fname = values.getasstring("firstname"); String lname = values.getasstring("lastname"); long id = mopenhelper.getwritabledatabase().insert("users", null, values); return Uri.withAppendedPath(CONTENT_URI, "" + id); We can insert() on our Users table, passing the values that need to be inserted...

110 Implementing the insert() method public class MyContentProvider extends ContentProvider {... public Uri insert(uri uri, ContentValues values) { String fname = values.getasstring("firstname"); String lname = values.getasstring("lastname"); long id = mopenhelper.getwritabledatabase().insert("users", null, values); Because the _ID column is the primary key, we don't need to specify a value for it. It will automatically be added for us return Uri.withAppendedPath(CONTENT_URI, "" + id);...

111 Implementing the insert() method public class MyContentProvider extends ContentProvider {... public Uri insert(uri uri, ContentValues values) { String fname = values.getasstring("firstname"); String lname = values.getasstring("lastname"); long id = mopenhelper.getwritabledatabase().insert("users", null, values); That _ID value is returned from the call to insert(), we store it in this long int return Uri.withAppendedPath(CONTENT_URI, "" + id);...

112 Implementing the insert() method public class MyContentProvider extends ContentProvider {... public Uri insert(uri uri, ContentValues values) { String fname = values.getasstring("firstname"); String lname = values.getasstring("lastname"); long id = mopenhelper.getwritabledatabase().insert("users", null, values);... return Uri.withAppendedPath(CONTENT_URI, "" + id); Here we return the Uri that can be used to identify the row that was just inserted. For example content://my.package.name.provider/users/1

113 Implementing the update() method public class MyContentProvider extends ContentProvider {... public int update(uri uri, ContentValues values, String selection, String[] selectionargs) { return mopenhelper.getwritabledatabase(). update("users", values, selection, selectionargs);...

114 Implementing the update() method public class MyContentProvider extends ContentProvider {... public int update(uri uri, ContentValues values, String selection, String[] selectionargs) {... return mopenhelper.getwritabledatabase(). update("users", values, selection, selectionargs); After checking for invalid values (not shown here), we simply use our mopenhelper to update the Users table, and return that value. Next we implement the delete() method

115 Implementing the delete() method public class MyContentProvider extends ContentProvider {... public int delete(uri uri, String whereclause, String[] whereargs) { return mopenhelper.getwritabledatabase(). delete(table_namestable, whereclause, whereargs);...

116 Implementing the delete() method public class MyContentProvider extends ContentProvider {... public int delete(uri uri, String whereclause, String[] whereargs) { return mopenhelper.getwritabledatabase(). delete(table_namestable, whereclause, whereargs); Next, we implement the query() method...

117 Implementing the delete() method public class MyContentProvider extends ContentProvider {... public Cursor query(uri table, String[] columns, String selection, String[] args, String orderby) {... return mopenhelper.getreadabledatabase().query("users", columns, selection, args, null, null, orderby);

118 Content Provider Permissions Now that you've set up your ContentProvider, you will want to have external apps require permission to read/write your data More on your own permissions here

119 Content Provider Permissions By default, anyone can read from or write to your ContentProvider Take the steps necessary to protect you data

120 Content Provider Permissions 1. Open the AndroidManifest.xml file 2. Add a <permission /> tag above the <application> tag 3. Set the android:name attribute for your permission my.package.name.provider.permission.read_permission (Create a String resource for this permission String) 4. Save the file You can add as many permission Strings you want, how you use them is more important

121 Content Provider Permissions Single read-write provider-level permission One permission that controls both read and write access to the entire provider, specified with the android:permission attribute of the <provider> element. Separate read and write provider-level permission android:readpermission android:writepermission They take precedence over the permission required by A read permission and a write permission for the entire provider android:permission.

122 Content Provider Permissions See ContentProviderExternalUserExample.tar Make sure that you've also installed ContentProviderExample.tar on the same device, so that the external user can use its content provider

123 Viewing ContentProvider data We want to create a class to view ContentProvider data when an application calls ACTION_VIEW Implement gettype() in ContentProvider to return MimeType Can have multiple Activities One displays single entry One displays list of entries

Database Development In Android Applications

Database Development In Android Applications ITU- FAO- DOA- TRCSL Training on Innovation & Application Development for E- Agriculture Database Development In Android Applications 11 th - 15 th December 2017 Peradeniya, Sri Lanka Shahryar Khan & Imran

More information

CS371m - Mobile Computing. Content Providers And Content Resolvers

CS371m - Mobile Computing. Content Providers And Content Resolvers 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

More information

ContentProvider & ContentResolver ContentResolver methods CursorLoader Implementing ContentProviders

ContentProvider & ContentResolver ContentResolver methods CursorLoader Implementing ContentProviders ContentProvider & ContentResolver ContentResolver methods CursorLoader Implementing ContentProviders Represents a repository of structured data Encapsulates data sets Enforces data access permissions Intended

More information

CS Android. Vitaly Shmatikov

CS Android. Vitaly Shmatikov CS 5450 Android Vitaly Shmatikov Structure of Android Applications Applications include multiple components Activities: user interface Services: background processing Content providers: data storage Broadcast

More information

How-to s and presentations. Be prepared to demo them in class. https://sites.google.com/site/androidhowto/presentati ons

How-to s and presentations. Be prepared to demo them in class. https://sites.google.com/site/androidhowto/presentati ons Upcoming Assignments Readings: Chapter 6 by today Lab 3 due today (complete survey) Lab 4 will be available Friday (due February 5) Friday Quiz in Blackboard 2:10-3pm (Furlough) Vertical Prototype due

More information

CSCU9YH: Development with Android

CSCU9YH: Development with Android : Development with Android Computing Science and Mathematics University of Stirling Data Storage and Exchange 1 Preferences: Data Storage Options a lightweight mechanism to store and retrieve keyvalue

More information

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

App Development for Smart Devices. Lec #5: Content Provider App Development for Smart Devices CS 495/595 - Fall 2011 Lec #5: Content Provider Tamer Nadeem Dept. of Computer Science Some slides adapted from Jussi Pohjolainen and Bob Kinney Objective Data Storage

More information

07. Data Storage

07. Data Storage 07. Data Storage 22.03.2018 1 Agenda Data storage options How to store data in key-value pairs How to store structured data in a relational database 2 Data Storage Options Shared Preferences Store private

More information

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

ContentProviders. CS 282 Principles of Operating Systems II Systems Programming for Android ContentProviders CS 282 Principles of Operating Systems II Systems Programming for Android ContentProviders manage access to a central repository of structured data & can make an app s data available to

More information

Eng. Jaffer M. El-Agha Android Programing Discussion Islamic University of Gaza. Data persistence

Eng. Jaffer M. El-Agha Android Programing Discussion Islamic University of Gaza. Data persistence Eng. Jaffer M. El-Agha Android Programing Discussion Islamic University of Gaza Data persistence Shared preferences A method to store primitive data in android as key-value pairs, these saved data will

More information

An Android Studio SQLite Database Tutorial

An Android Studio SQLite Database Tutorial An Android Studio SQLite Database Tutorial Previous Table of Contents Next An Android Studio TableLayout and TableRow Tutorial Understanding Android Content Providers in Android Studio Purchase the fully

More information

Automatically persisted among application sessions

Automatically persisted among application sessions STORAGE OPTIONS Storage options SharedPreference Small amount of data, as Key-value pairs Private to an Activity or Shared among Activities Internal storage Small to medium amount of data Private to the

More information

Learn about Android Content Providers and SQLite

Learn about Android Content Providers and SQLite Tampa Bay Android Developers Group Learn about Android Content Providers and SQLite Scott A. Thisse March 20, 2012 Learn about Android Content Providers and SQLite What are they? How are they defined?

More information

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

Content Provider. Introduction 01/03/2016. Session objectives. Content providers. Android programming course. Introduction. Built-in Content Provider Android programming course Session objectives Introduction Built-in Custom By Võ Văn Hải Faculty of Information Technologies 2 Content providers Introduction Content providers manage access to a structured

More information

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

Object-Oriented Databases Object-Relational Mappings and Frameworks. Alexandre de Spindler Department of Computer Science Object-Oriented Databases Object-Relational Mappings and Frameworks Challenges Development of software that runs on smart phones. Data needs to outlive program execution Use of sensors Integration with

More information

Mobile Application Development Android

Mobile Application Development Android Mobile Application Development Android Lecture 3 MTAT.03.262 Satish Srirama satish.srirama@ut.ee Android Lecture 2 - recap Views and Layouts Events Basic application components Activities Intents 9/15/2014

More information

Mobile and Ubiquitous Computing: Android Programming (part 4)

Mobile and Ubiquitous Computing: Android Programming (part 4) Mobile and Ubiquitous Computing: Android Programming (part 4) Master studies, Winter 2015/2016 Dr Veljko Pejović Veljko.Pejovic@fri.uni-lj.si Examples from: Mobile and Ubiquitous Computing Jo Vermeulen,

More information

Applied Cognitive Computing Fall 2016 Android Application + IBM Bluemix (Cloudant NoSQL DB)

Applied Cognitive Computing Fall 2016 Android Application + IBM Bluemix (Cloudant NoSQL DB) Applied Cognitive Computing Fall 2016 Android Application + IBM Bluemix (Cloudant NoSQL DB) In this exercise, we will create a simple Android application that uses IBM Bluemix Cloudant NoSQL DB. The application

More information

SharedPreferences Internal Storage External Storage SQLite databases

SharedPreferences Internal Storage External Storage SQLite databases SharedPreferences Internal Storage External Storage SQLite databases Use when you want to store small amounts of primitive data A persistent map that holds key-value pairs of simple data types Automatically

More information

Accelerating Information Technology Innovation

Accelerating Information Technology Innovation Accelerating Information Technology Innovation http://aiti.mit.edu Cali, Colombia Summer 2012 Lesson 8 Data binding and Databases Agenda Data Binding Databases in general Databases on Android (SQLite)

More information

Mobile Application Development Android

Mobile Application Development Android Mobile Application Development Android Lecture 3 MTAT.03.262 Satish Srirama satish.srirama@ut.ee Android Lecture 2 -recap Views and Layouts Events Basic application components Activities Intents BroadcastReceivers

More information

Managing Data. However, we'll be looking at two other forms of persistence today: (shared) preferences, and databases.

Managing Data. However, we'll be looking at two other forms of persistence today: (shared) preferences, and databases. Managing Data This week, we'll be looking at managing information. There are actually many ways to store information for later retrieval. In fact, feel free to take a look at the Android Developer pages:

More information

Change in Orientation. Marco Ronchetti Università degli Studi di Trento

Change in Orientation. Marco Ronchetti Università degli Studi di Trento 1 Change in Orientation Marco Ronchetti Università degli Studi di Trento Change in orientation Change in orientation For devices that support multiple orientations, Android detects a change in orientation:

More information

Agenda. Overview of Xamarin and Xamarin.Android Xamarin.Android fundamentals Creating a detail screen

Agenda. Overview of Xamarin and Xamarin.Android Xamarin.Android fundamentals Creating a detail screen Gill Cleeren Agenda Overview of Xamarin and Xamarin.Android Xamarin.Android fundamentals Creating a detail screen Lists and navigation Navigating from master to detail Optimizing the application Preparing

More information

Android Application Model II. CSE 5236: Mobile Application Development Instructor: Adam C. Champion, Ph.D. Course Coordinator: Dr.

Android Application Model II. CSE 5236: Mobile Application Development Instructor: Adam C. Champion, Ph.D. Course Coordinator: Dr. Android Application Model II CSE 5236: Mobile Application Development Instructor: Adam C. Champion, Ph.D. Course Coordinator: Dr. Rajiv Ramnath 1 Outline Activity Lifecycle Services Persistence Content

More information

Mobile Computing Practice # 2d Android Applications Local DB

Mobile Computing Practice # 2d Android Applications Local DB Mobile Computing Practice # 2d Android Applications Local DB In this installment we will add persistent storage to the restaurants application. For that, we will create a database with a table for holding

More information

Mobile Programming Lecture 3. Resources, Selection, Activities, Intents

Mobile Programming Lecture 3. Resources, Selection, Activities, Intents Mobile Programming Lecture 3 Resources, Selection, Activities, Intents Lecture 2 Review What widget would you use to allow the user to enter a yes/no value a range of values from 1 to 100 What's the benefit

More information

Android: Data Storage

Android: Data Storage Android: Data Storage F. Mallet Frederic.Mallet@unice.fr Université Nice Sophia Antipolis Outline Data Storage Shared Preferences Internal Storage External Storage SQLite Databases Network Connection F.

More information

SQLite. 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 6: Working with Databases. What is a Database Server. Advantages of SQLite

SQLite. 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 6: Working with Databases. What is a Database Server. Advantages of SQLite SQLite 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 6: Working with Databases Dr Dimitris C. Dracopoulos SQLite is a tiny yet powerful database engine. Besides Android, it can be found in: Apple iphone

More information

Android Programming - Jelly Bean

Android Programming - Jelly Bean 1800 ULEARN (853 276) www.ddls.com.au Android Programming - Jelly Bean Length 5 days Price $4235.00 (inc GST) Overview This intensive, hands-on five-day course teaches programmers how to develop activities,

More information

The Basis of Data. Steven R. Bagley

The Basis of Data. Steven R. Bagley The Basis of Data Steven R. Bagley So far How to create a UI View defined in XML Java-based Activity as the Controller Services Long running processes Intents used to send messages between things asynchronously

More information

Mobile Computing Practice # 2c Android Applications - Interface

Mobile Computing Practice # 2c Android Applications - Interface Mobile Computing Practice # 2c Android Applications - Interface One more step in the restaurants application. 1. Design an alternative layout for showing up in landscape mode. Our current layout is not

More information

Android Application Development

Android Application Development Android Application Development Octav Chipara What is Android A free, open source mobile platform A Linux-based, multiprocess, multithreaded OS Android is not a device or a product It s not even limited

More information

Data storage and exchange in Android

Data storage and exchange in Android Mobile App Development 1 Overview 2 3 SQLite Overview Implementation 4 Overview Methods to implement URI like SQL 5 Internal storage External storage Overview 1 Overview 2 3 SQLite Overview Implementation

More information

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

A Tour of Android. and some of it s APIs. Bryan Noll A Tour of Android and some of it s APIs Bryan Noll Me professionally A good starting point http://neidetcher.blogspot.com/2009/07/android-presentation-from-denver-open.html The OS The VM Basic Views Basic

More information

SQLite Database. References. Overview. Structured Databases

SQLite Database. References. Overview. Structured Databases SQLite Database References Android Developers Article https://developer.android.com/training/basics/data-storage/databases.html Android SQLite Package Reference https://developer.android.com/reference/android/database/sqlite/package-summary.html

More information

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

SharedPreference. <map> <int name=access_count value=3 /> </map> 1 Android Data Storage Options Android provides several data storage options for you to save persistent application data depends on your specific needs: private/public, small/large datasets :- Internal

More information

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar Mobile Application Development Higher Diploma in Science in Computer Science Produced by Eamonn de Leastar (edeleastar@wit.ie) Department of Computing, Maths & Physics Waterford Institute of Technology

More information

Creating a Custom ListView

Creating a Custom ListView Creating a Custom ListView References https://developer.android.com/guide/topics/ui/declaring-layout.html#adapterviews Overview The ListView in the previous tutorial creates a TextView object for each

More information

Android Specifics. Jonathan Diehl (Informatik 10) Hendrik Thüs (Informatik 9)

Android Specifics. Jonathan Diehl (Informatik 10) Hendrik Thüs (Informatik 9) Android Specifics Jonathan Diehl (Informatik 10) Hendrik Thüs (Informatik 9) Android Specifics ArrayAdapter Preferences Widgets Jonathan Diehl, Hendrik Thüs 2 ArrayAdapter Jonathan Diehl, Hendrik Thüs

More information

CS371m - Mobile Computing. Persistence - SQLite

CS371m - Mobile Computing. Persistence - SQLite CS371m - Mobile Computing Persistence - SQLite In case you have not taken 347: Data Management or worked with databases as part of a job, internship, or project: 2 Databases RDBMS relational data base

More information

Data storage overview SQLite databases

Data storage overview SQLite databases http://www.android.com/ Data storage overview SQLite databases Data storage overview Assets (assets) and Resources (res/raw) Private data installed with the application (read-only) Use the android.content.res.xxx

More information

Developing Android Applications Introduction to Software Engineering Fall Updated 1st November 2015

Developing Android Applications Introduction to Software Engineering Fall Updated 1st November 2015 Developing Android Applications Introduction to Software Engineering Fall 2015 Updated 1st November 2015 Android Lab 3 & Midterm Additional Concepts No Class Assignment 2 Class Plan Android : Additional

More information

Required Core Java for Android application development

Required Core Java for Android application development Required Core Java for Android application development Introduction to Java Datatypes primitive data types non-primitive data types Variable declaration Operators Control flow statements Arrays and Enhanced

More information

Writing Efficient Drive Apps for Android. Claudio Cherubino / Alain Vongsouvanh Google Drive Developer Relations

Writing Efficient Drive Apps for Android. Claudio Cherubino / Alain Vongsouvanh Google Drive Developer Relations Writing Efficient Drive Apps for Android Claudio Cherubino / Alain Vongsouvanh Google Drive Developer Relations Raise your hand if you use Google Drive source: "put your hands up!" (CC-BY) Raise the other

More information

Mobile Application Development Android

Mobile Application Development Android Mobile Application Development Android Lecture 3 MTAT.03.262 Satish Srirama satish.srirama@ut.ee Android Lecture 2 - recap Views and Layouts Events Basic application components Activities Intents 9/22/2017

More information

CS378 -Mobile Computing. Content Providers

CS378 -Mobile Computing. Content Providers CS378 -Mobile Computing Content Providers Content Providers One of the four primary application components: activities content providers services broadcast receivers 2 Android Applications Recall Each

More information

Diving into Android. By Jeroen Tietema. Jeroen Tietema,

Diving into Android. By Jeroen Tietema. Jeroen Tietema, Diving into Android By Jeroen Tietema Jeroen Tietema, 2015 1 Requirements 4 Android SDK 1 4 Android Studio (or your IDE / editor of choice) 4 Emulator (Genymotion) or a real device. 1 See https://developer.android.com

More information

Wireless Vehicle Bus Adapter (WVA) Android Library Tutorial

Wireless Vehicle Bus Adapter (WVA) Android Library Tutorial Wireless Vehicle Bus Adapter (WVA) Android Library Tutorial Revision history 90001431-13 Revision Date Description A October 2014 Original release. B October 2017 Rebranded the document. Edited the document.

More information

10.1 Introduction. Higher Level Processing. Word Recogniton Model. Text Output. Voice Signals. Spoken Words. Syntax, Semantics, Pragmatics

10.1 Introduction. Higher Level Processing. Word Recogniton Model. Text Output. Voice Signals. Spoken Words. Syntax, Semantics, Pragmatics Chapter 10 Speech Recognition 10.1 Introduction Speech recognition (SR) by machine, which translates spoken words into text has been a goal of research for more than six decades. It is also known as automatic

More information

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I) ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I) Lecture 3: Android Life Cycle and Permission Android Lifecycle An activity begins its lifecycle when entering the oncreate() state If not

More information

CS378 -Mobile Computing. Persistence -SQLite

CS378 -Mobile Computing. Persistence -SQLite CS378 -Mobile Computing Persistence -SQLite Databases RDBMS relational data base management system Relational databases introduced by E. F. Codd Turing Award Winner Relational Database data stored in tables

More information

CMSC436: Fall 2013 Week 4 Lab

CMSC436: Fall 2013 Week 4 Lab CMSC436: Fall 2013 Week 4 Lab Objectives: Familiarize yourself with Android Permission and with the Fragment class. Create simple applications using different Permissions and Fragments. Once you ve completed

More information

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar Mobile Application Development Higher Diploma in Science in Computer Science Produced by Eamonn de Leastar (edeleastar@wit.ie) Department of Computing, Maths & Physics Waterford Institute of Technology

More information

Accelerating Information Technology Innovation

Accelerating Information Technology Innovation Accelerating Information Technology Innovation http://aiti.mit.edu India Summer 2012 Review Session Android and Web Working with Views Working with Views Create a new Android project. The app name should

More information

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I) ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I) Lecture 3: Android Life Cycle and Permission Entire Lifetime An activity begins its lifecycle when entering the oncreate() state If not interrupted

More information

Lecture 2 Android SDK

Lecture 2 Android SDK Lecture 2 Android SDK This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/ or send a

More information

Adapter.

Adapter. 1 Adapter An Adapter object acts as a bridge between an AdapterView and the underlying data for that view The Adapter provides access to the data items The Adapter is also responsible for making a View

More information

Android development. Outline. Android Studio. Setting up Android Studio. 1. Set up Android Studio. Tiberiu Vilcu. 2.

Android development. Outline. Android Studio. Setting up Android Studio. 1. Set up Android Studio. Tiberiu Vilcu. 2. Outline 1. Set up Android Studio Android development Tiberiu Vilcu Prepared for EECS 411 Sugih Jamin 15 September 2017 2. Create sample app 3. Add UI to see how the design interface works 4. Add some code

More information

Android Programming Lecture 16 11/4/2011

Android Programming Lecture 16 11/4/2011 Android Programming Lecture 16 11/4/2011 New Assignment Discuss New Assignment for CityApp GetGPS Search Web Service Parse List Coordinates Questions from last class It does not appear that SQLite, in

More information

Mobile Programming Lecture 7. Dialogs, Menus, and SharedPreferences

Mobile Programming Lecture 7. Dialogs, Menus, and SharedPreferences Mobile Programming Lecture 7 Dialogs, Menus, and SharedPreferences Agenda Dialogs Menus SharedPreferences Android Application Components 1. Activity 2. Broadcast Receiver 3. Content Provider 4. Service

More information

Practical 1.ListView example

Practical 1.ListView example Practical 1.ListView example In this example, we show you how to display a list of fruit name via ListView. Android Layout file File : res/layout/list_fruit.xml

More information

Android App Development. Mr. Michaud ICE Programs Georgia Institute of Technology

Android App Development. Mr. Michaud ICE Programs Georgia Institute of Technology Android App Development Mr. Michaud ICE Programs Georgia Institute of Technology Android Operating System Created by Android, Inc. Bought by Google in 2005. First Android Device released in 2008 Based

More information

Mobile User Interfaces

Mobile User Interfaces Mobile User Interfaces CS 2046 Mobile Application Development Fall 2010 Announcements Next class = Lab session: Upson B7 Office Hours (starting 10/25): Me: MW 1:15-2:15 PM, Upson 360 Jae (TA): F 11:00

More information

EMBEDDED SYSTEMS PROGRAMMING Android Services

EMBEDDED SYSTEMS PROGRAMMING Android Services EMBEDDED SYSTEMS PROGRAMMING 2016-17 Android Services APP COMPONENTS Activity: a single screen with a user interface Broadcast receiver: responds to system-wide broadcast events. No user interface Service:

More information

Mobile Programming Lecture 5. Composite Views, Activities, Intents and Filters

Mobile Programming Lecture 5. Composite Views, Activities, Intents and Filters Mobile Programming Lecture 5 Composite Views, Activities, Intents and Filters Lecture 4 Review How do you get the value of a string in the strings.xml file? What are the steps to populate a Spinner or

More information

Single Application Persistent Data Storage. CS 282 Principles of Operating Systems II Systems Programming for Android

Single Application Persistent Data Storage. CS 282 Principles of Operating Systems II Systems Programming for Android Single Application Persistent Data Storage CS 282 Principles of Operating Systems II Systems Programming for Android Android offers several ways to store data Files SQLite database SharedPreferences Android

More information

Safety First - Android sicher programmieren! Benjamin Reimold & Stephan Linzner

Safety First - Android sicher programmieren! Benjamin Reimold & Stephan Linzner 2011 Safety First - Android sicher programmieren! Benjamin Reimold & Stephan Linzner 7th July, 2011 Introducing Stephan Linzner Benjamin Reimold Freelance Software Engineer Mobile Developer Founder of

More information

Android Programming Lecture 15 11/2/2011

Android Programming Lecture 15 11/2/2011 Android Programming Lecture 15 11/2/2011 City Web Service Documentation: http://206.219.96.5/webcatalog/ Need a web services client library: KSOAP2 Acts as our function calling proxy Allows us to generate

More information

Android HelloWorld - Example. Tushar B. Kute,

Android HelloWorld - Example. Tushar B. Kute, Android HelloWorld - Example Tushar B. Kute, http://tusharkute.com Anatomy of Android Application Anatomy of Android Application Java This contains the.java source files for your project. By default, it

More information

Islamic University of Gaza. Faculty of Engineering. Computer Engineering Department. Mobile Computing ECOM Eng. Wafaa Audah.

Islamic University of Gaza. Faculty of Engineering. Computer Engineering Department. Mobile Computing ECOM Eng. Wafaa Audah. Islamic University of Gaza Faculty of Engineering Computer Engineering Department Mobile Computing ECOM 5341 By Eng. Wafaa Audah July 2013 1 Launch activitits, implicit intents, data passing & start activity

More information

MyDatabaseHelper. public static final String TABLE_NAME = "tbl_bio";

MyDatabaseHelper. public static final String TABLE_NAME = tbl_bio; Page 1 of 5 MyDatabaseHelper import android.content.context; import android.database.sqlite.sqliteopenhelper; class MyDatabaseHelper extends SQLiteOpenHelper { private static final String DB_NAME = "friend_db";

More information

CS 234/334 Lab 1: Android Jump Start

CS 234/334 Lab 1: Android Jump Start CS 234/334 Lab 1: Android Jump Start Distributed: January 7, 2014 Due: Friday, January 10 or Monday, January 13 (in-person check off in Mobile Lab, Ry 167). No late assignments. Introduction The goal of

More information

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

Android Components Android Smartphone Programming. Outline University of Freiburg. Data Storage Database University of Freiburg. Notizen. Android Components Android Smartphone Programming Matthias Keil Institute for Computer Science Faculty of Engineering 4. November 2013 Outline 1 2 Messages to the User 3 Background Work 4 App Widgets 5

More information

Android Programs Day 5

Android Programs Day 5 Android Programs Day 5 //Android Program to demonstrate the working of Options Menu. 1. Create a New Project. 2. Write the necessary codes in the MainActivity.java to create OptionMenu. 3. Add the oncreateoptionsmenu()

More information

ListView Containers. Resources. Creating a ListView

ListView Containers. Resources. Creating a ListView ListView Containers Resources https://developer.android.com/guide/topics/ui/layout/listview.html https://developer.android.com/reference/android/widget/listview.html Creating a ListView A ListView is a

More information

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

M.C.A. Semester V Subject: - Mobile Computing (650003) Week : 2 M.C.A. Semester V Subject: - Mobile Computing (650003) Week : 2 1) What is Intent? How it is useful for transitioning between various activities? How intents can be received & broadcasted. (Unit :-2, Chapter

More information

App Development for Smart Devices. Lec #18: Advanced Topics

App Development for Smart Devices. Lec #18: Advanced Topics App Development for Smart Devices CS 495/595 - Fall 2011 Lec #18: Advanced Topics Tamer Nadeem Dept. of Computer Science Objective Web Browsing Android Animation Android Backup Presentation - Developing

More information

Intents. Your first app assignment

Intents. Your first app assignment Intents Your first app assignment We will make this. Decidedly lackluster. Java Code Java Code XML XML Preview XML Java Code Java Code XML Buttons that work

More information

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

Understand applications and their components. activity service broadcast receiver content provider intent AndroidManifest.xml Understand applications and their components activity service broadcast receiver content provider intent AndroidManifest.xml Android Application Written in Java (it s possible to write native code) Good

More information

Produced by. Design Patterns. MSc in Computer Science. Eamonn de Leastar

Produced by. Design Patterns. MSc in Computer Science. Eamonn de Leastar Design Patterns MSc in Computer Science Produced by Eamonn de Leastar (edeleastar@wit.ie) Department of Computing, Maths & Physics Waterford Institute of Technology http://www.wit.ie http://elearning.wit.ie

More information

Android User Interface Android Smartphone Programming. Outline University of Freiburg

Android User Interface Android Smartphone Programming. Outline University of Freiburg Android Smartphone Programming Matthias Keil Institute for Computer Science Faculty of Engineering 20. Oktober 2014 Outline 1 2 Multi-Language Support 3 Summary Matthias Keil 20. Oktober 2014 2 / 19 From

More information

Mobile Programming Lecture 2. Layouts, Widgets, Toasts, and Event Handling

Mobile Programming Lecture 2. Layouts, Widgets, Toasts, and Event Handling Mobile Programming Lecture 2 Layouts, Widgets, Toasts, and Event Handling Lecture 1 Review How to edit XML files in Android Studio? What holds all elements (Views) that appear to the user in an Activity?

More information

Mobile Application Development

Mobile Application Development Mobile Application Development donation-web api { method: 'GET', path: '/api/candidates', config: CandidatesApi.find, { method: 'GET', path: '/api/candidates/{id', config: CandidatesApi.findOne, { method:

More information

Screen Slides. The Android Studio wizard adds a TextView to the fragment1.xml layout file and the necessary code to Fragment1.java.

Screen Slides. The Android Studio wizard adds a TextView to the fragment1.xml layout file and the necessary code to Fragment1.java. Screen Slides References https://developer.android.com/training/animation/screen-slide.html https://developer.android.com/guide/components/fragments.html Overview A fragment can be defined by a class and

More information

Upon completion of the second part of the lab the students will have:

Upon completion of the second part of the lab the students will have: ETSN05, Fall 2017, Version 2.0 Software Development of Large Systems Lab 2 1. INTRODUCTION The goal of lab 2 is to introduce students to the basics of Android development and help them to create a starting

More information

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

Produced by. Mobile Application Development. David Drohan Department of Computing & Mathematics Waterford Institute of Technology Mobile Application Development Produced by David Drohan (ddrohan@wit.ie) Department of Computing & Mathematics Waterford Institute of Technology http://www.wit.ie The image cannot be displayed. Your computer

More information

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

Android Application Development 101. Jason Chen Google I/O 2008 Android Application Development 101 Jason Chen Google I/O 2008 Goal Get you an idea of how to start developing Android applications Introduce major Android application concepts Provide pointers for where

More information

INTRODUCTION TO ANDROID

INTRODUCTION TO ANDROID INTRODUCTION TO ANDROID 1 Niv Voskoboynik Ben-Gurion University Electrical and Computer Engineering Advanced computer lab 2015 2 Contents Introduction Prior learning Download and install Thread Android

More information

CS 4518 Mobile and Ubiquitous Computing Lecture 4: Data-Driven Views, Android Components & Android Activity Lifecycle Emmanuel Agu

CS 4518 Mobile and Ubiquitous Computing Lecture 4: Data-Driven Views, Android Components & Android Activity Lifecycle Emmanuel Agu CS 4518 Mobile and Ubiquitous Computing Lecture 4: Data-Driven Views, Android Components & Android Activity Lifecycle Emmanuel Agu Announcements Group formation: Projects 2, 3 and final project will be

More information

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar Mobile Application Development Higher Diploma in Science in Computer Science Produced by Eamonn de Leastar (edeleastar@wit.ie) Department of Computing, Maths & Physics Waterford Institute of Technology

More information

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

Android System Architecture. Android Application Fundamentals. Applications in Android. Apps in the Android OS. Program Model 8/31/2015 Android System Architecture Android Application Fundamentals Applications in Android All source code, resources, and data are compiled into a single archive file. The file uses the.apk suffix and is used

More information

Solving an Android Threading Problem

Solving an Android Threading Problem Home Java News Brief Archive OCI Educational Services Solving an Android Threading Problem Introduction by Eric M. Burke, Principal Software Engineer Object Computing, Inc. (OCI) By now, you probably know

More information

THE CATHOLIC UNIVERSITY OF EASTERN AFRICA A. M. E. C. E. A

THE CATHOLIC UNIVERSITY OF EASTERN AFRICA A. M. E. C. E. A THE CATHOLIC UNIVERSITY OF EASTERN AFRICA A. M. E. C. E. A MAIN EXAMINATION P.O. Box 62157 00200 Nairobi - KENYA Telephone: 891601-6 Fax: 254-20-891084 E-mail:academics@cuea.edu AUGUST - DECEMBER 2016

More information

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar Mobile Application Development Higher Diploma in Science in Computer Science Produced by Eamonn de Leastar (edeleastar@wit.ie) Department of Computing, Maths & Physics Waterford Institute of Technology

More information

Lecture 14. Android Application Development

Lecture 14. Android Application Development Lecture 14 Android Application Development Notification Instructor Muhammad Owais muhammad.owais@riphah.edu.pk Cell: 03215500223 Notifications Used to notify user for events Three general forms of Notifications

More information

Our First Android Application

Our First Android Application Mobile Application Development Lecture 04 Imran Ihsan Our First Android Application Even though the HelloWorld program is trivial in introduces a wealth of new ideas the framework, activities, manifest,

More information

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Saving State

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Saving State EMBEDDED SYSTEMS PROGRAMMING 2016-17 Application Tip: Saving State THE PROBLEM How to save the state (of a UI, for instance) so that it survives even when the application is closed/killed The state should

More information

<uses-permission android:name="android.permission.internet"/>

<uses-permission android:name=android.permission.internet/> Chapter 11 Playing Video 11.1 Introduction We have discussed how to play audio in Chapter 9 using the class MediaPlayer. This class can also play video clips. In fact, the Android multimedia framework

More information

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

Produced by. Mobile Application Development. David Drohan Department of Computing & Mathematics Waterford Institute of Technology Mobile Application Development Produced by David Drohan (ddrohan@wit.ie) Department of Computing & Mathematics Waterford Institute of Technology http://www.wit.ie User Interface Design" & Development -

More information