Back to project page DialQuick_Android.
The source code is released under:
GNU General Public License
If you think the Android project DialQuick_Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.blogspot.techzealous.ui; // w w w. j ava 2 s . c o m import java.util.ArrayList; import android.app.Activity; import android.content.Intent; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.provider.ContactsContract; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.ListView; import com.blogspot.techzealous.dialquick.DialQuickConstants; import com.blogspot.techzealous.dialquick.R; public class ContactsActivity extends Activity { private int code = 1; private static ArrayList<String> phonesList = new ArrayList<String>(); private ListView phones; private int viewId; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.contactsdialquick); Intent i = new Intent(Intent.ACTION_PICK, Uri.parse("content://contacts/people")); startActivityForResult(i, code); } public void onResume() { super.onResume(); phones = (ListView) findViewById(R.id.listViewContacts); viewId = android.R.layout.simple_list_item_1; ArrayAdapter<String> phonesAdapter = new ArrayAdapter<String>( ContactsActivity.this, viewId, phonesList); phones.setAdapter(phonesAdapter); phones.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int item, long arg3) { Intent i = new Intent(); i.putExtra(DialQuickConstants.PREF_TEL_NUMBER, phonesList.get(item)); ContactsActivity.this.setResult(Activity.RESULT_OK, i); finish(); } }); } public void onPause() { super.onPause(); phonesList.clear(); } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == code && resultCode == Activity.RESULT_OK) { Uri contact = data.getData(); Cursor cursor = managedQuery(contact, null, null, null, null); if (cursor.moveToFirst()) { String contactId = cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Contacts._ID)); Cursor phones = managedQuery(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId, null, null); while (phones.moveToNext()) { String number = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); phonesList.add(number); } } } else { finish(); } } }