Hey, I'd like to know if there is a way to know if the content provider of callings has changed. I mean, if I make a call, or I answer a call, it returns a "flag" that a new log has been added to the call log, or the place where Android store informations about callings.
Because, when I make a call, Android stores the number, the contact name(if exists), the hour of the calling, the duration, blah blah blah, all in the content provider. So is there a way to capture this "flag" that says the content provider of callings is bigger, I mean, that a new data has been inserted on the content provider CallLog.Calls.
(Updated)
So, I still have a lot of doubts related to this issue. I don't know where to register the content observer. My intention is when something change in the CallLog content provider, the insert method of the code will be used.
I mean, the code wont do anything unless new data has been added to the CallLog content provider. If some data has been added to the CallLog content provider, then the code will query the new data, and then will insert. I wanna do this because withou a Content observer the application was inserting data in the database that was already inserted every time I run the application, got it?
So here is my code. If someone could tell me where to put the registerContentObserver and everything else is needed I thank you.
package com.psyhclo;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import com.psyhclo.R;
import com.psyhclo.CallDataHelper.OpenHelper;
import android.app.Activity;
import android.app.ListActivity;
import android.database.ContentObserver;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.os.Handler;
import android.provider.ContactsContract.RawContacts;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.content.ContentValues;
import android.content.Context;
import android.content.ContentProvider;
public class RatedCalls extends ListActivity {
private SQLiteDatabase db;
private CallDataHelper dh = null;
StringBuilder sb = new StringBuilder();
OpenHelper openHelper = new OpenHelper(RatedCalls.this);
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Cursor cursor = getContentResolver().query(
android.provider.CallLog.Calls.CONTENT_URI, null, null, null,
android.provider.CallLog.Calls.DATE + " DESC ");
dh = new CallDataHelper(this);
db = openHelper.getWritableDatabase();
startManagingCursor(cursor);
int numberColumnId = cursor
.getColumnIndex(android.provider.CallLog.Calls.NUMBER);
int durationId = cursor
.getColumnIndex(android.provider.CallLog.Calls.DURATION);
int contactNameId = cursor
.getColumnIndex(android.provider.CallLog.Calls.CACHED_NAME);
int dateId = cursor.getColumnIndex(android.provider.CallLog.Calls.DATE);
int numTypeId = cursor
.getColumnIndex(android.provider.CallLog.Calls.CACHED_NUMBER_TYPE);
Date dt = new Date();
int hours = dt.getHours();
int minutes = dt.getMinutes();
int seconds = dt.getSeconds();
String currTime = hours + ":" + minutes + ":" + seconds;
ArrayList<String> callList = new ArrayList<String>();
if (cursor.moveToFirst()) {
do {
String contactNumber = cursor.getString(numberColumnId);
String contactName = cursor.getString(contactNameId);
String duration = cursor.getString(durationId);
String callDate = DateFormat.getDateInstance().format(dateId);
String numType = cursor.getString(numTypeId);
ContentValues values = new ContentValues();
values.put("contact_id", 1);
values.put("contact_name", contactName);
values.put("number_type", numType);
values.put("contact_number", contactNumber);
values.put("duration", duration);
values.put("date", callDate);
values.put("current_time", currTime);
values.put("cont", 1);
this.db.insert(CallDataHelper.TABLE_NAME, null, values);
Toast.makeText(getBaseContext(), "Inserted!", Toast.LENGTH_LONG);
callList.add("Contact Number: " + contactNumber
+ "\nContact Name: " + contactName + "\nDuration: "
+ duration + "\nDate: " + callDate);
} while (cursor.moveToNext());
}
setListAdapter(new ArrayAdapter<String>(this, R.layout.listitem,
callList));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(getApplicationContext(),
((TextView) view).getText(), Toast.LENGTH_SHORT).show();
}
});
}
}
Have a look at the method registerContentObserver() in the ContentResolver class. This allows you to register a callback if the dataset behind the content provider changes.
See also this blog posting for a working example how to observe a content provider for changes.
Related
04-24 12:15:21.671: E/AndroidRuntime(26419):java.lang.RuntimeException: Unable to start activity ComponentInfo{com.flocator/com.flocater.Friendfinderactivity}:android.database.sqlite.SQLiteException: near "null": syntax error(code 1): , while compiling: select * from null
This is the error I am getting every time I am trying to compile..I am a learning android so I don't know much about this...so can anyone help me to fix this issue..
and I am also getting error Source not found
so can you help me to sort out with these two problems.
The codes are In Friendfnderactivity.java
package com.flocater;
import com.flocator.R;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
public class Friendfinderactivity extends Activity {
/** Called when the activity is first created. */
public static String deviceid = "deviceid";
public static String device_id = "device_id";
public static String user_id = "user_id";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DBHelper dbhelper = new DBHelper(this);
SQLiteDatabase db = dbhelper.getWritableDatabase();
TelephonyManager tm = (TelephonyManager) this
.getSystemService(Context.TELEPHONY_SERVICE);
deviceid = tm.getDeviceId();
Cursor cursor = db.rawQuery("select * from "
+ Database.SUBSCRIBE_TABLE_NAME, null);
int rows = cursor.getCount();
if (rows > 0) {
cursor.moveToFirst();
user_id = cursor.getString(0);
device_id = cursor.getString(3);
}
db.close();
if (device_id.equals(deviceid)) {
setContentView(R.layout.subscriber);
} else
setContentView(R.layout.subscribe);
}
public void subscribeUser(View v) {
// get access to views
EditText editName = (EditText) this.findViewById(R.id.editName);
EditText editPhone = (EditText) this.findViewById(R.id.editPhone);
EditText editArea = (EditText) this.findViewById(R.id.editArea);
EditText editCity = (EditText) this.findViewById(R.id.editCity);
boolean done = Database.addUser(this, editName.getText().toString(),
editPhone.getText().toString(), deviceid, editArea.getText()
.toString(), editCity.getText().toString());
if(done) {
Toast.makeText(this, "Subscribed Successfully!", Toast.Length_Long).show();
Intent intent = new Intent(this,Friendfinderactivity.class);
startActivity(intent);
}
else
Toast.makeText(this, "Sorry! Could not subscribe!", Toast.LENGTH_LONG).show();
}
public void addFriends(View v) {
Intent intent = new Intent(this,AddFriends.class);
startActivity(intent);
}
public void viewFriends(View v) {
Intent intent = new Intent(this,SeeFriends.class);
startActivity(intent);
}
}
The error is clear "select * from null" That is your SQL query
Here the table name is null.
You just needs to add the table name.
For example
replace the following line with
Cursor cursor = db.rawQuery("select * from "
+ Database.SUBSCRIBE_TABLE_NAME, null);
this
Cursor cursor = db.rawQuery("select * from your_table_name", null);
I am just telling the error you modify for your need.
I want to implement a program which inserts details in database everytime the call is made or sms is sent. Should I use a broadcast receiver or content observer or Service ? what would be appropriate? I am new to android and urgently need help on this.
I have done the following code uptill now. The problem with this is when first time the code is run then for example call log has 8 records so these 8 records are inserted in database. Then if any change in call log is made for example i make another call then 17 records are shown in database instead of 9. Please help where am i going wrong ?
package com.calllogdb;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.content.ContentValues;
import android.database.ContentObserver;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import android.view.Menu;
import android.widget.Toast;
//import static android.provider.BaseColumns._ID;
import static com.calllogdb.Constants.KEY_ContactNum ;
import static com.calllogdb.Constants.KEY_ContactName;
import static com.calllogdb.Constants.KEY_Duration;
import static com.calllogdb.Constants.KEY_Date ;
import static com.calllogdb.Constants.KEY_NumType ;
import static com.calllogdb.Constants.KEY_CurrTime ;
import static com.calllogdb.Constants.TABLE_NAME;
public class MainActivity extends Activity {
private Helper helper = new Helper(this);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.getApplicationContext()
.getContentResolver()
.registerContentObserver(
android.provider.CallLog.Calls.CONTENT_URI, true,
new CallLogObserver(new Handler()));
try {
addLog();
}
finally {
helper.close();
}
}
private void addLog() {
// TODO Auto-generated method stub
SQLiteDatabase db;
Cursor cursor = getContentResolver().query(
android.provider.CallLog.Calls.CONTENT_URI, null, null, null,
android.provider.CallLog.Calls.DATE + " DESC ");
db = helper.getWritableDatabase();
startManagingCursor(cursor);
int numberColumnId = cursor.getColumnIndex(android.provider.CallLog.Calls.NUMBER);
int durationId = cursor.getColumnIndex(android.provider.CallLog.Calls.DURATION);
int contactNameId = cursor.getColumnIndex(android.provider.CallLog.Calls.CACHED_NAME);
int dateId = cursor.getColumnIndex(android.provider.CallLog.Calls.DATE);
int numTypeId = cursor.getColumnIndex(android.provider.CallLog.Calls.CACHED_NUMBER_TYPE);
Date dt = new Date();
int hours = dt.getHours();
int minutes = dt.getMinutes();
int seconds = dt.getSeconds();
String currTime = hours + ":" + minutes + ":" + seconds;
ArrayList<String> callList = new ArrayList<String>();
if (cursor.moveToFirst()) {
do {
String contactNumber = cursor.getString(numberColumnId);
String contactName = cursor.getString(contactNameId);
String duration = cursor.getString(durationId);
String callDate = DateFormat.getDateInstance().format(dateId);
String numType = cursor.getString(numTypeId);
ContentValues values = new ContentValues();
values.put(KEY_ContactName, contactName);
values.put(KEY_NumType, numType);
values.put(KEY_ContactNum, contactNumber);
values.put(KEY_Duration, duration);
values.put(KEY_Date, callDate);
values.put(KEY_CurrTime, currTime);
db.insert(TABLE_NAME, null, values);
callList.add("Contact Number: " + contactNumber
+ "\nContact Name: " + contactName + "\nDuration: "
+ duration + "\nDate: " + callDate);
} while (cursor.moveToNext());
}
Toast.makeText(getBaseContext(), "Inserted!", Toast.LENGTH_LONG).show();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public class CallLogObserver extends ContentObserver
{
public CallLogObserver(Handler handler) {
super(handler);
// TODO Auto-generated constructor stub
}
#Override
public boolean deliverSelfNotifications() {
return true;
}
#Override
public void onChange(boolean selfChange) {
Log.d("LOG_TAG", "MyContentObserver.onChange( " + selfChange
+ ")");
super.onChange(selfChange);
addLog();
}
}
}
Whenever i am making a call it gets notified and inserts whole set of records instead of only the latest one.What should i do to prevent this?
Thanks
You are probably inserting the whole call log into the database again. You can use either content observer or a broadcast listener to know that a call is made, but you need to maintain the time when you last read the complete db of call logs, and only insert calls that are made after that time.
If you use contentobserver, the observer needs to be in a service. Register the observer in the onCreate(). You will use contentProvider in the onChange of the contentObserver. You will need to maintain time when you last read the database using shared preferences. Note the changes of entries after the time stored in shared preferences. Now update the time of shared preferences to current time. Also unregister the content observer in onDestroy().
I have a contact picker list with chckboxes of the contacts that have a phone number.
Now, my problem is that can't seem to get the checked contact's name and phone number.
Here is my code:
import android.app.ListActivity;
import android.content.ContentResolver;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.util.Log;
import android.util.SparseBooleanArray;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
public class Create_Group extends ListActivity implements OnClickListener{
// List variables
public String[] Contacts = {};
public int[] to = {};
public ListView myListView;
Button save_button;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.create_group);
// Initializing the buttons according to their ID
save_button = (Button)findViewById(R.id.save_group_button);
// Defines listeners for the buttons
save_button.setOnClickListener(this);
Cursor mCursor = getContacts();
startManagingCursor(mCursor);
ListAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_multiple_choice, mCursor,
Contacts = new String[] {ContactsContract.Contacts.DISPLAY_NAME },
to = new int[] { android.R.id.text1 });
setListAdapter(adapter);
myListView = getListView();
myListView.setItemsCanFocus(false);
myListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
}
private Cursor getContacts() {
// Run query
Uri uri = ContactsContract.Contacts.CONTENT_URI;
String[] projection = new String[] { ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME};
String selection = ContactsContract.Contacts.HAS_PHONE_NUMBER + " = '"
+ ("1") + "'";
String[] selectionArgs = null;
String sortOrder = ContactsContract.Contacts.DISPLAY_NAME
+ " COLLATE LOCALIZED ASC";
return managedQuery(uri, projection, selection, selectionArgs,
sortOrder);
}
public void onClick(View src) {
Intent i;
switch (src.getId())
{
case R.id.save_group_button:
int checked_Names_Counter = 0;
// Goes over the list of contacts and checks which were checked
for (int j = 0; j < myListView.getCount(); j++)
{
if (myListView.isItemChecked(j) == true)
{
Cursor cur = getContacts();
ContentResolver contect_resolver = getContentResolver();
cur.moveToFirst();
/**
* Here I tried to compare the IDs but each list has different IDs so it didn't really help me...
// Converts the current checked name ID into a String
String Checked_ID = String.valueOf(myListView.getCheckedItemIds()[checked_Names_Counter]);
// Checks if the current checked ID matches the cursors ID, if not move the cursor to the next name
while (Checked_ID != cur.getString(cur.getColumnIndexOrThrow(ContactsContract.Contacts._ID)))
{
cur.moveToNext();
}
*/
/**
* Here I tried to compare the names, even though it's not a good pratice, and it didn't work either...
String Checked_Name = myListView.getAdapter().getItem(checked_Names_Counter).toString();
// Checks if the current checked ID matches the cursors ID, if not move the cursor to the next name
while (Checked_Name != cur.getString(cur.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME)))
{
cur.moveToNext();
}
*/
String id = cur.getString(cur.getColumnIndexOrThrow(ContactsContract.Contacts._ID));
String name = "";
String no = "";
Cursor phoneCur = contect_resolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[] { id }, null);
name = phoneCur.getString(phoneCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
no = phoneCur.getString(phoneCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
id = null;
name = null;
no = null;
phoneCur = null;
checked_Names_Counter++;
}
}
// Goes back to the Manage Groups screen
i = new Intent(this, Manage_Groups.class);
startActivity(i);
break;
}
}
}
Any ideas?
Thanks!!
It looks like you are so close, I used ListView.getCheckedItemIds() to return unique ids of the selected contacts:
public void onClick(View view) {
long[] ids = myListView.getCheckedItemIds();
for(long id : ids) {
Cursor contact = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[] { id + "" }, null);
// Do whatever you want with the data
}
}
Addition
I have a quick question about this code:
// Goes back to the Manage Groups screen
i = new Intent(this, Manage_Groups.class);
startActivity(i);
Does this bring the user back to a previous Activity? If so you should use finish(); instead. finish() ends the current Activity, taking it off the stack and freeing up any memory (less memory wasted means a faster app.) It also allows the previous Activity to restore the saved state when it left (filled in EditTexts, previous Spinner selections, toggle button and checkmarks, etc.) The Activity resumes where the user left off.
I am trying to fetch contact numbers in my application but it is showing only id and display name. Can anyone correct it? I don't know how to fetch the contact numbers. I am only trying to fetch the contact numbers not to add the contact numbers.
package com.data;
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.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
public final class ContactManager extends Activity
{
public static final String TAG = "ContactManager";
private Button mAddAccountButton;
private ListView mContactList;
private boolean mShowInvisible;
private CheckBox mShowInvisibleControl;
/**
* Called when the activity is first created. Responsible for initializing the UI.
*/
#Override
public void onCreate(Bundle savedInstanceState)
{
Log.v(TAG, "Activity State: onCreate()");
super.onCreate(savedInstanceState);
setContentView(R.layout.contact_manager);
// Obtain handles to UI objects
// mAddAccountButton = (Button) findViewById(R.id.addContactButton);
mContactList = (ListView) findViewById(R.id.contactList);
mShowInvisibleControl = (CheckBox) findViewById(R.id.showInvisible);
// Initialize class properties
mShowInvisible = false;
mShowInvisibleControl.setChecked(mShowInvisible);
// Register handler for UI elements
mShowInvisibleControl.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Log.d(TAG, "mShowInvisibleControl changed: " + isChecked);
mShowInvisible = isChecked;
populateContactList();
}
});
// Populate the contact list
populateContactList();
}
private void populateContactList() {
Cursor cursor = getContacts();
String[] pno=new String[cursor.getCount()];
if(cursor.getCount()>0)
{
int i=0;
if(cursor.moveToFirst())
{
do
{
pno[i++]=(String)cursor.getString(0).toString() +" "+ (String)cursor.getString(1);
}while(cursor.moveToNext());
}
}
ArrayAdapter<String> adapter=new ArrayAdapter<String>(ContactManager.this,android.R.layout.simple_list_item_1,pno);
mContactList.setAdapter(adapter);
}
private Cursor getContacts()
{
// Run query
Uri uri = ContactsContract.Contacts.CONTENT_URI;
String[] projection = new String[] {
ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME,
};
String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '" +
(mShowInvisible ? "0" : "1") + "'";
String[] selectionArgs = null;
String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
return managedQuery(uri, projection, selection, selectionArgs, sortOrder);
}
}
Modify your query projection to include also the ContactsContract.Contacts.HAS_PHONE_NUMBER column.
Then, inside the do-while loop, you can do:
String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
String hasPhone = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
if (Integer.parseInt(hasPhone) > 0) {
Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "=" + contactId, null, null);
String phoneNumber;
while (cursor.moveToNext()) { //iterate over all contact phone numbers
phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
}
phones.close();
}
You need to use another content provider uri. I will point you to one answer of mine, so that I don't repeat myself in stackoverflow: https://stackoverflow.com/a/8646827/1108032. In this answer I fetch the name out of the phone number, but I really believe you can revert it easily.
You should use the Phone Uri or the new PhoneLookUp Uri to get display name and all phone numbers with contact id.
http://developer.android.com/reference/android/provider/ContactsContract.PhoneLookup.html
I am having trouble getting a contact phone number, i keep getting an error in the log cat saying
02-24 19:40:42.772: ERROR/CursorWindow(21467): Bad request for field slot 0,-1. numRows = 1, numColumns = 24
here is my code
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.widget.Button;
import android.widget.SimpleCursorAdapter;
import android.os.Bundle;
public class Contacts extends Activity {
private ListView mContactList;
private Button mAddContact;
private boolean mShowInvisible = false;
boolean set;
public String name = "";
public String id;
public String phone;
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.contact_listview);
mContactList = (ListView) findViewById(R.id.contactList);
mAddContact = (Button) findViewById(R.id.addContactButton);
mAddContact.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(i,1);
}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent data){
if(resultCode == RESULT_OK){
getContactData(data);
}
}
public void getContactData(Intent data){
ContentResolver cr = getContentResolver();
Uri contactData = data.getData();
Log.v("Contact", contactData.toString());
Cursor c = managedQuery(contactData,null,null,null,null);
if(c.moveToFirst()){
id = c.getString(c.getColumnIndex(ContactsContract.Contacts._ID));
Log.v("Contact", "ID: " + id.toString());
name = c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
Log.v("Contact", "Name: " + name.toString());
if (Integer.parseInt(c.getString(c.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
Cursor pCur = cr.query(Phone.CONTENT_URI,null,Phone.CONTACT_ID +" = ?", new String[]{id}, null);
while(pCur.moveToNext()){
phone = c.getString(c.getColumnIndex(Phone.NUMBER));
Log.v("getting phone number", "Phone Number: " + phone);
}
}
}
}
everything reads fine up until the point where i try to get the phone number
Shouldn't it be:
while(pCur.moveToNext()){
phone = pCur.getString(pCur.getColumnIndex(Phone.NUMBER));
Log.v("getting phone number", "Phone Number: " + phone);
}
That is, pCur instead of the 'c' cursor, which holds the contacts?
You need to reset the cursor before calling "moveToNext()". Just call "pCur.moveToFirst();" right before the while. That should help.
i got it, i took out the while loop and i get the number fine now