SlideShare a Scribd company logo
Workshop India
» Content providers allow programs access to data
  which is present on the device.

» A content provider manages access to a central
  repository of data.

» They encapsulate the data from tables, and provide
  mechanisms for defining data security and unified
  usage.

» Content providers are the standard interface that
  connects data in one process with code running in
  another process.
Content Provider   Intended Data
Browser            Browser bookmarks, browser
                   history, etc.
CallLog            Missed calls, call details, etc.
Contacts           Contact details
MediaStore         Media files such as audio, video
                   and images
Settings           Device settings and preferences
» Irrespective of how the data is stored, Content
  Providers give a uniform interface to access the data.

» Data is exposed as a simple table with rows and
  columns where row is a record and column is a
  particular data type with a specific meaning.

» Each record is identified by a unique _ID field which is
  the key to the record.

» Each content provider exposes a unique URI that
  identifies its data set uniquely. URI == table-name
» First we need to create a layout and activity class.

» In our layout we need to create a ListView.

» Create a cursor to query the phone database for
  the contacts..

» Use an adaptor to send the results to the view for
  displaying
» An application accesses the data from a content
  provider with a ContentResolver client object.

» The ContentResolver methods provide the basic
  "CRUD" (create, retrieve, update, and delete)
  functions of persi

          // Queries the user dictionary and returns results
          mCursor = getContentResolver().query(
             UserDictionary.Words.CONTENT_URI, // The content URI of the words table
             mProjection,                       // The columns to return for each row
             mSelectionClause                     // Selection statement
             mSelectionArgs,                    // Selection criteria
             mSortOrder);                        // The sort order for the returned rows
» A content URI is a URI that identifies data in a
  provider.

» Content URIs include the symbolic name of the
  entire provider (its authority) and a name that
  points to a table (a path).

» content://user_dictionary/words
» To retrieve data from a provider, your application
  needs "read access permission" for the provider in
  androidmanifest.xml.

» Construct the query
   ˃ A "projection" defines the columns that will be returned for each row

   ˃ Do a query and return a cursor object which holds the result returned from the
     database


» Read the result with the cursor implementation
   ˃   you can iterate over the rows in the results
   ˃   determine the data type of each column
   ˃   get the data out of a column
   ˃   And more!
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  >
  <ListView android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>
</LinearLayout>
                         This would create a listView of id list in the layout.
» Cursor is an interface that provides random read-write access
  to the result of a database query from a content provider.

» A cursor is a collection of rows

» All field access methods are based on column number. You have
  to convert column name to a column number first

» Random means (you can move forward and backwards)

» You can also find size / traverse result set easily.

             Cursor cur;
             for(cur.moveToFirst();!cur.isAfterLast();cur.moveToNext()) {
             //access methods
             }
» Since a Cursor is a "list" of rows, a good way to
  display the contents of a Cursor is to link it to
  a ListView via an adaptor.


       // Creates a new SimpleCursorAdapter
       mCursorAdapter = new SimpleCursorAdapter(
          getApplicationContext(),          // The application's Context object
          R.layout.wordlistrow,           // A layout in XML for one row in the ListView
          mCursor,                           // The result from the query
          mWordListColumns,               // A string array of column names in the cursor
          mWordListItems,                   // An integer array of view IDs in the row layout
          0);                               // Flags (usually none are needed)

       // Sets the adapter for the ListView
       mWordList.setAdapter(mCursorAdapter);
Since our activity consists of a list, we can extend the class
public class MyActivity extends ListActivity
                                                       ListActivity to make life easier.
{
  ListView lv;
  Cursor Cursor1;        lv is used to manage the Listview, note that since the layout contains only one listview,
                       the extend ListActivity is enough for the connection.
  @Override
  public void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);                    A projection is the specific columns of the
    setContentView(R.layout.main);                         table that we want to query.
    String [] projection = new String[] { Phone.DISPLAY_NAME,
         Phone.NUMBER,
         Phone._ID                                  getContentResolver() – returns a ContentResolver object
    };                                              from the activity class that can be used to query the
                                                 content databases with
    Cursor1 = getContentResolver().query(        query(projection, selection, selectionargs, sortorder)
        Phone.CONTENT_URI,
        projection,
        null,
        null,                                Phone.CONTENT_URI :
        Phone.DISPLAY_NAME + " ASC");        (android.provider.ContactsContract.CommonDataKinds.Phone)
                                             Points to the contact database location
    startManagingCursor(Cursor1);
startManagingCursor(Cursor1);         From and to are used to convert between the
                                                  result of the query in the cursor to the textview’s
            String[] from = {                     in a list layout
            Phone.DISPLAY_NAME,
            Phone.NUMBER,
                                                                               SimpleCursorAdapter maps columns
            Phone._ID};                                                        from a cursor to TextViews or
                                                                               ImageViews defined in an XML file.
            int[] to = {android.R.id.text1, android.R.id.text2};               Cursor1, from, to are the respective data
                                                                               args
            SimpleCursorAdapter listadapter = new SimpleCursorAdapter(this,
                                        android.R.layout.simple_list_item_2,
                                        Cursor1, from, to );

             setListAdapter(listadapter);
                                                             android.R.layout.simple_list_item_2 is an inbuilt
            lv = getListView();                              layout with 2 textviews for a list.

                                                             A custom XML layout in res/layout can be inserted
} // onCreate ends here
                                                             here too with the id names of the textveiws replaced
                                                             in the to variable.
[…]

                                                                Get the cursor object and
cursor = managedQuery(EXTERNAL_CONTENT_URI,                     perform the query on it
                  proj, selection, arg, sort);

                                                   Find the listview view from
list = (ListView) findViewById(R.id.List01);       the view


list.setAdapter(new N_Adapter(getApplicationContext(), cursor));

[..]
                              Use this function to bind the listview to an adaptor of
                              class N_Adapter..

                              The function is taking a constructor to this class as
                              arguments
public class N_Adapter extends BaseAdapter {     This class extends BaseAdapter which is the base
    private Context mContext;                    class for all adapter implementations
    Cursor cursor;

    public N_Adapter(Context c,Cursor m) {      This constructor takes in the arguments passed to it
      mContext = c;                             and returns the object to the setadapter method.
      cursor = m;
    }

    public int getCount() {
      return count;
    }

    public Object getItem(int position) {
      return position;                         These functions are required for the adapter to work
    }                                          properly within the android subsystem

    public long getItemId(int position) {
      return position;
    }
This function performs
                                                                                               the binding between the
public View getView(int position, View convertView, ViewGroup parent) {                        cursor and the listview.
      TextView tv;
      View row;                                         The view row is used to hold the xml file to place the
      LayoutInflater inflater = getLayoutInflater();    listview’s contents in.

          if (convertView == null) {                                     convertView is in case the inflated view is being
             row = inflater.inflate(android.R.layout.item, null);        passed in as arguments, in this case – we don’t
         } else                                                          want to inflate again..
             row = convertView;                                          android.R.layout.item -> xml file for the list
                                                                         elements
         tv = (TextView) row.findViewById(R.id.TextView01);

         cursor.moveToPosition(position);
         music_column_index = cursor .getColumnIndexOrThrow(People.DISPLAY_NAME);
         id = cursor.getString(music_column_index);
                                                                    Cursor is a class member initialized by the
         tv.setText(id);                                            argument to the constructor, these lines extract
         return row;                                                the data required and pass it to the textView
     }                                                              element in the listview XML file.
 }
» Create a large text white background contacts list.

» Attach an on click event to each list item and open
  a new activity that shows that contact’s details

» Make an application that allows you to enter a
  phrase and searches through the SMS messages
  for all sms’s containing that text.
» Make a edittext view in a layout and load it in
  activity.

» Make a button and bind an onclickhandler() to it

» When the button is clicked, load sms from the
  content provider and search the contents for all
  messages containing that word.

» Display all messages (one by one or in a listview as
  per your choice)
» <uses-permission
  android:name="android.permission.READ_SMS"></uses-permission>
» <uses-permission
  android:name="android.permission.READ_CONTACTS"></uses-
  permission>


»   URI for sms content providers is as follows
»   Inbox = "content://sms/inbox"
»   Failed = "content://sms/failed"
»   Queued = "content://sms/queued"
»   Sent = "content://sms/sent"
»   Draft = "content://sms/draft"
»   Outbox = "content://sms/outbox"
»   Undelivered = "content://sms/undelivered"
»   All = "content://sms/all"
»   Conversations = "content://sms/conversations"
»   addressCol= mCurSms.getColumnIndex("address");
»   personCol= mCurSms.getColumnIndex("person");
»   dateCol = mCurSms.getColumnIndex("date");
»   protocolCol= mCurSms.getColumnIndex("protocol");
»   readCol = mCurSms.getColumnIndex("read");
»   statusCol = mCurSms.getColumnIndex("status");
»   typeCol = mCurSms.getColumnIndex("type");
»   subjectCol = mCurSms.getColumnIndex("subject");
»   bodyCol = mCurSms.getColumnIndex("body");
» Uri uri = Uri.parse("content://sms/inbox");

» Cursor c= getContentResolver().query(uri, null,
  null ,null,null);

» startManagingCursor(c)
body = new String[c.getCount()];
number = new String[c.getCount()];

if(c.moveToFirst()){
     for(int i=0;i<c.getCount();i++){
           body[i]= c.getString(c.getColumnIndexOrThrow("body")).toString();
           number[i]=c.getString(c.getColumnIndexOrThrow("address")).toString();
           c.moveToNext();
     }
}
c.close();
» Understand the application and do proper
  research online!

» This example has some concepts that you have to
  figure out on your own.

» Use documentation, books provided and other
  online resources to code the application.

» Ask help in online forums also!

More Related Content

PPTX
Content provider in_android
PPT
android content providers
PPT
Content providers in Android
ODP
Android App Development - 10 Content providers
PPTX
Android Training (Content Provider)
PDF
Android contentprovider
PPTX
Android content providers
PPTX
Custom content provider in android
Content provider in_android
android content providers
Content providers in Android
Android App Development - 10 Content providers
Android Training (Content Provider)
Android contentprovider
Android content providers
Custom content provider in android

What's hot (20)

PPTX
Android Insights - 3 [Content Providers]
PPTX
Android content provider explained
PPTX
Android Training Session 1
PPT
Lecture14Slides.ppt
PDF
Android - Saving data
PDF
Backendless apps
PDF
Data Binding and Data Grid View Classes
PPTX
Ch 7 data binding
PPT
ASP.NET 08 - Data Binding And Representation
DOCX
Show loader to open url in web view
PDF
Lab2-android
PPT
Level 1 &amp; 2
PDF
BioJS specification document
PPT
Level 4
PPT
Level 3
PDF
WPF DATA BINDING CHEATSHEET V1.1
PPTX
Ado.net
ODP
Android App Development - 04 Views and layouts
PPTX
Create an android app for database creation using.pptx
PDF
Asp net interview_questions
Android Insights - 3 [Content Providers]
Android content provider explained
Android Training Session 1
Lecture14Slides.ppt
Android - Saving data
Backendless apps
Data Binding and Data Grid View Classes
Ch 7 data binding
ASP.NET 08 - Data Binding And Representation
Show loader to open url in web view
Lab2-android
Level 1 &amp; 2
BioJS specification document
Level 4
Level 3
WPF DATA BINDING CHEATSHEET V1.1
Ado.net
Android App Development - 04 Views and layouts
Create an android app for database creation using.pptx
Asp net interview_questions
Ad

Similar to 05 content providers - Android (20)

PDF
Day 8: Dealing with Lists and ListViews
PDF
Cursor & Content Value.pdf
PPT
Spring data ii
PDF
How to become an Android dev starting from iOS (and vice versa)
PPTX
List adapter with multiple objects
PDF
Custom UI Components at Android Only 2011
ODP
Session 2- day 3
PPTX
SCWCD : The servlet container : CHAP : 4
PDF
EclipseCon2011 Cross-Platform Mobile Development with Eclipse
PPT
Coherence SIG: Advanced usage of indexes in coherence
PPT
Pavel_Kravchenko_Mobile Development
PDF
Android ui adapter
PDF
Taming Core Data by Arek Holko, Macoscope
PDF
Murach: How to transfer data from controllers
PDF
Angular.js Primer in Aalto University
PDF
Need help coding MorseCode in JavaCreate Class MorseCodeClient. T.pdf
PDF
Stata cheatsheet programming
PPT
collections
PDF
Underscore.js
Day 8: Dealing with Lists and ListViews
Cursor & Content Value.pdf
Spring data ii
How to become an Android dev starting from iOS (and vice versa)
List adapter with multiple objects
Custom UI Components at Android Only 2011
Session 2- day 3
SCWCD : The servlet container : CHAP : 4
EclipseCon2011 Cross-Platform Mobile Development with Eclipse
Coherence SIG: Advanced usage of indexes in coherence
Pavel_Kravchenko_Mobile Development
Android ui adapter
Taming Core Data by Arek Holko, Macoscope
Murach: How to transfer data from controllers
Angular.js Primer in Aalto University
Need help coding MorseCode in JavaCreate Class MorseCodeClient. T.pdf
Stata cheatsheet programming
collections
Underscore.js
Ad

More from Wingston (20)

PPTX
OpenCV @ Droidcon 2012
PPTX
04 activities - Android
PPTX
03 layouts & ui design - Android
PPTX
02 hello world - Android
PPTX
01 introduction & setup - Android
PPTX
OpenCV with android
PPTX
C game programming - SDL
PPTX
C programming - Pointers
PPTX
Introduction to Basic C programming 02
PPT
Introduction to Basic C programming 01
PPTX
Linux – an introduction
PPTX
Embedded linux
PPTX
04 Arduino Peripheral Interfacing
PPTX
03 analogue anrduino fundamentals
PPTX
02 General Purpose Input - Output on the Arduino
PPTX
Introduction to the Arduino
PPTX
4.content mgmt
PPTX
8 Web Practices for Drupal
PPTX
7 Theming in Drupal
PPTX
6 Special Howtos for Drupal
OpenCV @ Droidcon 2012
04 activities - Android
03 layouts & ui design - Android
02 hello world - Android
01 introduction & setup - Android
OpenCV with android
C game programming - SDL
C programming - Pointers
Introduction to Basic C programming 02
Introduction to Basic C programming 01
Linux – an introduction
Embedded linux
04 Arduino Peripheral Interfacing
03 analogue anrduino fundamentals
02 General Purpose Input - Output on the Arduino
Introduction to the Arduino
4.content mgmt
8 Web Practices for Drupal
7 Theming in Drupal
6 Special Howtos for Drupal

Recently uploaded (20)

PDF
Classroom Observation Tools for Teachers
PPTX
master seminar digital applications in india
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
Pharma ospi slides which help in ospi learning
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Cell Structure & Organelles in detailed.
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
Insiders guide to clinical Medicine.pdf
PPTX
Institutional Correction lecture only . . .
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Basic Mud Logging Guide for educational purpose
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Classroom Observation Tools for Teachers
master seminar digital applications in india
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Renaissance Architecture: A Journey from Faith to Humanism
Pharma ospi slides which help in ospi learning
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
Week 4 Term 3 Study Techniques revisited.pptx
Final Presentation General Medicine 03-08-2024.pptx
Cell Structure & Organelles in detailed.
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Complications of Minimal Access Surgery at WLH
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Insiders guide to clinical Medicine.pdf
Institutional Correction lecture only . . .
VCE English Exam - Section C Student Revision Booklet
PPH.pptx obstetrics and gynecology in nursing
Basic Mud Logging Guide for educational purpose
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES

05 content providers - Android

  • 2. » Content providers allow programs access to data which is present on the device. » A content provider manages access to a central repository of data. » They encapsulate the data from tables, and provide mechanisms for defining data security and unified usage. » Content providers are the standard interface that connects data in one process with code running in another process.
  • 3. Content Provider Intended Data Browser Browser bookmarks, browser history, etc. CallLog Missed calls, call details, etc. Contacts Contact details MediaStore Media files such as audio, video and images Settings Device settings and preferences
  • 4. » Irrespective of how the data is stored, Content Providers give a uniform interface to access the data. » Data is exposed as a simple table with rows and columns where row is a record and column is a particular data type with a specific meaning. » Each record is identified by a unique _ID field which is the key to the record. » Each content provider exposes a unique URI that identifies its data set uniquely. URI == table-name
  • 5. » First we need to create a layout and activity class. » In our layout we need to create a ListView. » Create a cursor to query the phone database for the contacts.. » Use an adaptor to send the results to the view for displaying
  • 6. » An application accesses the data from a content provider with a ContentResolver client object. » The ContentResolver methods provide the basic "CRUD" (create, retrieve, update, and delete) functions of persi // Queries the user dictionary and returns results mCursor = getContentResolver().query( UserDictionary.Words.CONTENT_URI, // The content URI of the words table mProjection, // The columns to return for each row mSelectionClause // Selection statement mSelectionArgs, // Selection criteria mSortOrder); // The sort order for the returned rows
  • 7. » A content URI is a URI that identifies data in a provider. » Content URIs include the symbolic name of the entire provider (its authority) and a name that points to a table (a path). » content://user_dictionary/words
  • 8. » To retrieve data from a provider, your application needs "read access permission" for the provider in androidmanifest.xml. » Construct the query ˃ A "projection" defines the columns that will be returned for each row ˃ Do a query and return a cursor object which holds the result returned from the database » Read the result with the cursor implementation ˃ you can iterate over the rows in the results ˃ determine the data type of each column ˃ get the data out of a column ˃ And more!
  • 9. <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="fill_parent"/> </LinearLayout> This would create a listView of id list in the layout.
  • 10. » Cursor is an interface that provides random read-write access to the result of a database query from a content provider. » A cursor is a collection of rows » All field access methods are based on column number. You have to convert column name to a column number first » Random means (you can move forward and backwards) » You can also find size / traverse result set easily. Cursor cur; for(cur.moveToFirst();!cur.isAfterLast();cur.moveToNext()) { //access methods }
  • 11. » Since a Cursor is a "list" of rows, a good way to display the contents of a Cursor is to link it to a ListView via an adaptor. // Creates a new SimpleCursorAdapter mCursorAdapter = new SimpleCursorAdapter( getApplicationContext(), // The application's Context object R.layout.wordlistrow, // A layout in XML for one row in the ListView mCursor, // The result from the query mWordListColumns, // A string array of column names in the cursor mWordListItems, // An integer array of view IDs in the row layout 0); // Flags (usually none are needed) // Sets the adapter for the ListView mWordList.setAdapter(mCursorAdapter);
  • 12. Since our activity consists of a list, we can extend the class public class MyActivity extends ListActivity ListActivity to make life easier. { ListView lv; Cursor Cursor1; lv is used to manage the Listview, note that since the layout contains only one listview, the extend ListActivity is enough for the connection. @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); A projection is the specific columns of the setContentView(R.layout.main); table that we want to query. String [] projection = new String[] { Phone.DISPLAY_NAME, Phone.NUMBER, Phone._ID getContentResolver() – returns a ContentResolver object }; from the activity class that can be used to query the content databases with Cursor1 = getContentResolver().query( query(projection, selection, selectionargs, sortorder) Phone.CONTENT_URI, projection, null, null, Phone.CONTENT_URI : Phone.DISPLAY_NAME + " ASC"); (android.provider.ContactsContract.CommonDataKinds.Phone) Points to the contact database location startManagingCursor(Cursor1);
  • 13. startManagingCursor(Cursor1); From and to are used to convert between the result of the query in the cursor to the textview’s String[] from = { in a list layout Phone.DISPLAY_NAME, Phone.NUMBER, SimpleCursorAdapter maps columns Phone._ID}; from a cursor to TextViews or ImageViews defined in an XML file. int[] to = {android.R.id.text1, android.R.id.text2}; Cursor1, from, to are the respective data args SimpleCursorAdapter listadapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2, Cursor1, from, to ); setListAdapter(listadapter); android.R.layout.simple_list_item_2 is an inbuilt lv = getListView(); layout with 2 textviews for a list. A custom XML layout in res/layout can be inserted } // onCreate ends here here too with the id names of the textveiws replaced in the to variable.
  • 14. […] Get the cursor object and cursor = managedQuery(EXTERNAL_CONTENT_URI, perform the query on it proj, selection, arg, sort); Find the listview view from list = (ListView) findViewById(R.id.List01); the view list.setAdapter(new N_Adapter(getApplicationContext(), cursor)); [..] Use this function to bind the listview to an adaptor of class N_Adapter.. The function is taking a constructor to this class as arguments
  • 15. public class N_Adapter extends BaseAdapter { This class extends BaseAdapter which is the base private Context mContext; class for all adapter implementations Cursor cursor; public N_Adapter(Context c,Cursor m) { This constructor takes in the arguments passed to it mContext = c; and returns the object to the setadapter method. cursor = m; } public int getCount() { return count; } public Object getItem(int position) { return position; These functions are required for the adapter to work } properly within the android subsystem public long getItemId(int position) { return position; }
  • 16. This function performs the binding between the public View getView(int position, View convertView, ViewGroup parent) { cursor and the listview. TextView tv; View row; The view row is used to hold the xml file to place the LayoutInflater inflater = getLayoutInflater(); listview’s contents in. if (convertView == null) { convertView is in case the inflated view is being row = inflater.inflate(android.R.layout.item, null); passed in as arguments, in this case – we don’t } else want to inflate again.. row = convertView; android.R.layout.item -> xml file for the list elements tv = (TextView) row.findViewById(R.id.TextView01); cursor.moveToPosition(position); music_column_index = cursor .getColumnIndexOrThrow(People.DISPLAY_NAME); id = cursor.getString(music_column_index); Cursor is a class member initialized by the tv.setText(id); argument to the constructor, these lines extract return row; the data required and pass it to the textView } element in the listview XML file. }
  • 17. » Create a large text white background contacts list. » Attach an on click event to each list item and open a new activity that shows that contact’s details » Make an application that allows you to enter a phrase and searches through the SMS messages for all sms’s containing that text.
  • 18. » Make a edittext view in a layout and load it in activity. » Make a button and bind an onclickhandler() to it » When the button is clicked, load sms from the content provider and search the contents for all messages containing that word. » Display all messages (one by one or in a listview as per your choice)
  • 19. » <uses-permission android:name="android.permission.READ_SMS"></uses-permission> » <uses-permission android:name="android.permission.READ_CONTACTS"></uses- permission> » URI for sms content providers is as follows » Inbox = "content://sms/inbox" » Failed = "content://sms/failed" » Queued = "content://sms/queued" » Sent = "content://sms/sent" » Draft = "content://sms/draft" » Outbox = "content://sms/outbox" » Undelivered = "content://sms/undelivered" » All = "content://sms/all" » Conversations = "content://sms/conversations"
  • 20. » addressCol= mCurSms.getColumnIndex("address"); » personCol= mCurSms.getColumnIndex("person"); » dateCol = mCurSms.getColumnIndex("date"); » protocolCol= mCurSms.getColumnIndex("protocol"); » readCol = mCurSms.getColumnIndex("read"); » statusCol = mCurSms.getColumnIndex("status"); » typeCol = mCurSms.getColumnIndex("type"); » subjectCol = mCurSms.getColumnIndex("subject"); » bodyCol = mCurSms.getColumnIndex("body");
  • 21. » Uri uri = Uri.parse("content://sms/inbox"); » Cursor c= getContentResolver().query(uri, null, null ,null,null); » startManagingCursor(c)
  • 22. body = new String[c.getCount()]; number = new String[c.getCount()]; if(c.moveToFirst()){ for(int i=0;i<c.getCount();i++){ body[i]= c.getString(c.getColumnIndexOrThrow("body")).toString(); number[i]=c.getString(c.getColumnIndexOrThrow("address")).toString(); c.moveToNext(); } } c.close();
  • 23. » Understand the application and do proper research online! » This example has some concepts that you have to figure out on your own. » Use documentation, books provided and other online resources to code the application. » Ask help in online forums also!