AddressBook Picker

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

AddressBook Picker

Postby chaoz1336 » Wed Jan 14, 2009 2:08 pm

Hey Guys,

I need some Informations about the addressbook in android.
Is there any existing solution for picking up a single contact via a gui in android?
When not, how can I access the AddressBook in Android an fill a list with it... (or sth ^^ )


thx in advance! :D
chaoz1336
Experienced Developer
Experienced Developer
 
Posts: 90
Joined: Wed Dec 10, 2008 5:19 pm

Top

Postby Emmanuel7 » Thu Jan 15, 2009 1:33 am

This code display the contact list in a list view, and call a contact when you press its name.

Change the called activity to do whatever you want with the contact :

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. package com.android.MyCaller;
  3.  
  4.  
  5.  
  6. import android.app.ListActivity;
  7.  
  8. import android.content.ContentUris;
  9.  
  10. import android.content.Intent;
  11.  
  12. import android.database.Cursor;
  13.  
  14. import android.os.Bundle;
  15.  
  16. import android.provider.Contacts.People;
  17.  
  18. import android.view.View;
  19.  
  20. import android.widget.ListAdapter;
  21.  
  22. import android.widget.ListView;
  23.  
  24. import android.widget.SimpleCursorAdapter;
  25.  
  26.  
  27.  
  28. public class MyCaller extends ListActivity {
  29.  
  30.    
  31.  
  32.      private ListAdapter mAdapter;
  33.  
  34.      
  35.  
  36.       /** Called when the activity is first created. */
  37.  
  38.     @Override
  39.  
  40.     public void onCreate(Bundle icicle) {
  41.  
  42.         super.onCreate(icicle);
  43.  
  44.         Cursor c = getContentResolver().query(People.CONTENT_URI, null, null, null, null);
  45.  
  46.         startManagingCursor(c);
  47.  
  48.        
  49.  
  50.         String[] columns = new String[]{People.NAME};
  51.  
  52.        
  53.  
  54.         mAdapter = new SimpleCursorAdapter(this,
  55.  
  56.                                                 android.R.layout.simple_list_item_1,
  57.  
  58.                                                 c,
  59.  
  60.                                                 columns,
  61.  
  62.                                                 new int[] {android.R.id.text1} );
  63.  
  64.        
  65.  
  66.         this.setListAdapter(mAdapter);
  67.  
  68.     }
  69.  
  70.    
  71.  
  72.     @Override
  73.  
  74.     protected void onListItemClick(ListView l, View v, int position, long id){
  75.  
  76.      super.onListItemClick(l, v, position, id);
  77.  
  78.      
  79.  
  80.      Intent i = new Intent(Intent.ACTION_CALL);
  81.  
  82.      
  83.  
  84.      Cursor c = (Cursor) mAdapter.getItem(position);
  85.  
  86.      long phoneID = c.getLong(c.getColumnIndex(People.PRIMARY_PHONE_ID));
  87.  
  88.      
  89.  
  90.      i.setData(ContentUris.withAppendedId(
  91.  
  92.           android.provider.Contacts.Phones.CONTENT_URI, phoneID));
  93.  
  94.      
  95.  
  96.      this.startActivity(i);
  97.  
  98.     }
  99.  
  100. }
  101.  
  102.  
Parsed in 0.038 seconds, using GeSHi 1.0.8.4
Emmanuel7
Senior Developer
Senior Developer
 
Posts: 164
Joined: Fri Dec 12, 2008 2:17 am
Location: Paris

Postby chaoz1336 » Thu Jan 15, 2009 11:15 am

*thumbs up*

great... thx :D


but... I still got a prob =/

as I want 2 start this programm I got an Error @ the line
" Cursosr c = getContentResolver().query(People.CONTENT_URI, null, null, null, null); "

can it be, that I cant start the programm as a single activity?

greetz n thx in advance!
chaoz1336
Experienced Developer
Experienced Developer
 
Posts: 90
Joined: Wed Dec 10, 2008 5:19 pm

Postby chaoz1336 » Mon Jan 19, 2009 12:48 pm

emmanuel? =/
Need ya help... (see above ^^ )
chaoz1336
Experienced Developer
Experienced Developer
 
Posts: 90
Joined: Wed Dec 10, 2008 5:19 pm

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 4 guests