hi frnds I have a button and a text view in the whole view, when I click the button, then all contacts are sve in the csv file, but I wnt when these contacts are collected in a CSV file, it updates the text as "export 3 (this is count changemeans 1 2 3 4 5 .... to the full number of contacts) contcts "means that the text view changes when I press the button, and then how to do it
code to get the total no. contacts in the phone below ...
update:
@Override
protected Boolean doInBackground(String... args) {
int count;
CSVWriter writer = null;
try
{
writer = new CSVWriter(new FileWriter(Environment.getExternalStorageDirectory().getAbsolutePath() + "/my_test_contact.csv"));
} catch (IOException e1) {
e1.printStackTrace();
}
String displayName;
String number;
String emailid;
long _id;
String columns[] = new String[]{ ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME };
writer.writeColumnNames();
Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,
columns,
null,
null,
ContactsContract.Data.DISPLAY_NAME + " COLLATE LOCALIZED ASC");
startManagingCursor(cursor);
if(cursor.moveToFirst()) {
do {
_id = Long.parseLong(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID)));
displayName = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)).trim();
number = getPrimaryNumber(_id);
emailid=getEmailid(_id);
writer.writeNext((displayName + "/" + number+ "/" + emailid).split("/"));
}
while(cursor.moveToNext());
csv_status = true;
} else {
csv_status = false;
}
try {
if(writer != null)
writer.close();
} catch (IOException e)
{
Log.w("Test", e.toString());
}
return null;
}
source
share