Query data from the Contacts content provider
Android ships with a number of content providers for common data types (audio, video, images, personal contact information, and so on). You can see some of them listed in the android.provider package. You can query these providers for the data they contain (although, for some, you must acquire the proper permission to read the data).
Example to Query data from the Contacts content provider
Example to Query data from the Contacts content provider
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
| package com.GetContact; import android.app.Activity; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.provider.Contacts.People; import android.widget.TextView; public class GetContactActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.main); TextView tvContacts = (TextView)findViewById(R.id.contacts); String[] contacts = new String[] {People.NAME, People.NUMBER}; Uri contentUri = People.CONTENT_URI; Cursor cursor = managedQuery(contentUri, contacts, null , null , null ); String textContacts = "" ; if (cursor.moveToFirst()) { String myname = null ; String mynumber = null ; do { textContacts = textContacts + cursor.getString(cursor.getColumnIndex(People.NAME)) + " : " + cursor.getString(cursor.getColumnIndex(People.NUMBER)) + "\n" ; } while (cursor.moveToNext()); tvContacts.setText(textContacts); } } }
akm www.cdacians.com |
No comments:
Post a Comment