Hi Skullmonkey,
Here's a better example of using that function. If you looked closely at my texting example, the names are kept in an array with a flag, name, number. This routine goes through the contacts list and picks out everyone with a mobile number, assembles them into one gigantic comma delimited string, and returns it to the caller. It initially sets all the flags to zero, anticipating that only a few would be turned on for a list of recipients. In this case, I take the string and parse it into the array I need for making the calls.
- Code: Select all
public String getContacts() {
ContentResolver cr = getContentResolver();
Cursor qc = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
String sr = "";
String s ="";
String s1 = "";
if (qc.moveToFirst()) {
do {
s = qc.getString(qc.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
s = clean(s);
int type = qc.getInt(qc.getColumnIndex(Phone.TYPE));
if (type == Phone.TYPE_MOBILE) {
s1 = qc.getString(qc.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
s1 = clean(s1);
if (sr.length()!=0) sr = sr+"\n";
sr = sr+"0,"+s+","+s1;
}//got a mobile
}//do
while (qc.moveToNext());
Log.e("CONTACT","File "+sr);
}//if
return sr;
}//getcontacts
public String clean(String in) {
String s = in.replaceAll(",", "_");
return s.replaceAll("\n", " ");
}//clean
If I remember correctly, your code for getting numbers from the contact list is all entangled with a simple list adapter and not easily intercepted for editing or inspecting, things like that. You could make an array for a spinner from a string like this and understand it better I think. But for a full fledged listview with its own adapter and xml and stuff this kind of string and eventual array works pretty good. The other reason I keep it in a string like this is so it can be stored and reloaded to fill a list of recipients that is different from other lists of recipients and the contact list.
I tend to work on everything at once and immediately have a plan how the whole thing fits together.
In this case for instance:
The main screen is a grid of buttons (no real limit) that allows you to send to a group when each button is pressed. You can also change the mode of that screen to allow you to edit the recipient list, the messages that you can send to that particular list and the name of the button itself.
I did establish early on that when a group was selected, you would also have to select a message if there was a choice of messages to send which this system would allow.
There would be two additional list activities where you can edit the items in them.
And finally when it sends, it passes that to a service that runs a thread to send so that you can call it and forget it, maybe even have more than one list being called at a time. Although you might have to check for duplicates but maybe not.
I didn't send these examples as tutorials. You are right about that. These are just code out of projects for the most part. I use T2J to store all these things and then kind of forget about them. When I need one, I create a project in T2J and copy/paste the code out of there. Parts of this will undoubtedly end up there. As for the market, there's already oodles of these kind of apps around so you'll probably have to promote your niche. Just naming it might be somewhat of a challenge.
Glad to see you're still working at it. Hope this helps.
Phyll