I am new to the android.Here I am create the apps such as read the phone contacts and stored into the csv file format file .It takes a long time to read contacts..In mean time i am need to use the progress bar until the file is writing the contacts details.Now i am confused that where can i insert the progress bar in my code..
My coding is...
private String getPrimaryNumber(long _id) {
String primaryNumber = null;
try {
Cursor cursor = getContentResolver().query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
new String[]{Phone.NUMBER, Phone.TYPE},
ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ _id, // We need to add more selection for phone type
null,
null);
if(cursor != null) {
while(cursor.moveToNext()){
switch(cursor.getInt(cursor.getColumnIndex(Phone.TYPE))){
case Phone.TYPE_MOBILE :
primaryNumber = cursor.getString(cursor.getColumnIndex(Phone.NUMBER));
break;
case Phone.TYPE_HOME :
primaryNumber = cursor.getString(cursor.getColumnIndex(Phone.NUMBER));
break;
case Phone.TYPE_WORK :
primaryNumber = cursor.getString(cursor.getColumnIndex(Phone.NUMBER));
break;
case Phone.TYPE_OTHER :
}
if(primaryNumber != null)
break;
}
}
} catch (Exception e) {
Log.i("test", "Exception " + e.toString());
} finally {
if(cursor != null) {
cursor.deactivate();
cursor.close();
}
}
return primaryNumber;
}
It is the code to read the contacts from the phone.In that coding where i can add the progress bar... please help anyone.. thanks in advance.