im beggin u help me

Put your problem here if it does not fit any of the other categories.

im beggin u help me

Postby jessmalade » Mon Nov 09, 2009 12:59 pm

hi every body,i need to get email from contact application, so when i click an item in the listeview of contacts i can get his email ,i tried a lot of codes but without result,please help
jessmalade
Freshman
Freshman
 
Posts: 3
Joined: Mon Nov 09, 2009 12:38 pm

Top

Postby ExxKA » Mon Nov 09, 2009 1:26 pm

Hey Jessmalade.

If you have solved the problem, please post a reply to this thread, or else other people searching for the same solution will get stuck and not notis the thread by umair solving the issue ([http://www.anddev.org/accessing_contacts_email_addresses-t5330.html])

Thank you.
Student at the IT-University of Copenhagen
Visit my blog 1337h4x0r.com
ExxKA
Developer
Developer
 
Posts: 29
Joined: Tue Nov 03, 2009 7:16 pm
Location: Denmark

get email from contact application

Postby jessmalade » Mon Nov 09, 2009 1:32 pm


this the code of our friend umar, i thank him very very much





import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.ExpandableListActivity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Contacts;
import android.view.View;
import android.widget.ExpandableListAdapter;
import android.widget.SimpleExpandableListAdapter;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ExpandableListView.OnChildClickListener;

public class cont extends ExpandableListActivity implements
OnChildClickListener {

private ExpandableListAdapter listAdapter;
private final String GROUP_NAME = "contactName";
private final String CHILD_NAME = "contactEmail";
private final String CHILD2_NAME = "contactNumber";

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// create a uri to access contacts
Uri mContacts = Contacts.ContactMethods.CONTENT_URI;

// select the columns that we wish to get in query
String[] projection = new String[] {Contacts.ContactMethods.PERSON_ID,Contacts.ContactMethods.DISPLAY_NAME,Contacts.ContactMethods.KIND, Contacts.ContactMethods.DATA };

// create a cursor which holds query results (like ResultSet in java)
Cursor c = this.managedQuery(mContacts, projection, null, null,Contacts.ContactMethods.DISPLAY_NAME + " ASC");

List<Map<String, String>> groups = new ArrayList<Map<String, String>>();
List<List<Map<String, String>>> children = new ArrayList<List<Map<String, String>>>();

List<Map<String, String>> childrenForAGroup = new ArrayList<Map<String, String>>();

// move to the first row of the results table
c.moveToFirst();
int previousId = -1;

do {
int personId = c.getInt(c
.getColumnIndex(Contacts.ContactMethods.PERSON_ID));

// if this person is already added in list, do not add again but
// just add it's information
if (personId != previousId) {
String personName = c.getString(c
.getColumnIndex(Contacts.ContactMethods.DISPLAY_NAME));

Map<String, String> groupMap = new HashMap<String, String>();
groupMap.put(GROUP_NAME, personName);
groups.add(groupMap);

if (previousId != -1) {
children.add(childrenForAGroup);
childrenForAGroup = new ArrayList<Map<String, String>>();
}
}

int dataKind = c.getInt(c.getColumnIndex(Contacts.ContactMethods.KIND));

// Pick only data with id=1 which represents email address
if (dataKind == 1) {String personEmail = c.getString(c.getColumnIndex(Contacts.ContactMethods.DATA));

Map<String, String> curChildMap = new HashMap<String, String>();
curChildMap.put(CHILD_NAME, personEmail);
childrenForAGroup.add(curChildMap);
}

previousId = personId;

} while (c.moveToNext());

// add the last set of children to the children's list
children.add(childrenForAGroup);

// find out the indexes of empty children lists and remove them and
// their respective groups
List indexes = this.findEmptyChildrenLists(children);
for (int i = 0; i < indexes.size(); i++) {
groups.remove(Integer.parseInt(indexes.get(i).toString()));
children.remove(Integer.parseInt(indexes.get(i).toString()));
}

// Set up list adapter
listAdapter = new SimpleExpandableListAdapter(this, groups,
android.R.layout.simple_expandable_list_item_1,
new String[] { GROUP_NAME }, new int[] { android.R.id.text1 },
children, android.R.layout.simple_expandable_list_item_1,
new String[] { CHILD_NAME }, new int[] { android.R.id.text1 });
setListAdapter(listAdapter);
}

private List findEmptyChildrenLists(List<?> list) {
List indexes = new ArrayList();
for (int i = 0; i < list.size(); i++) {
if (((List<?>) list.get(i)).isEmpty()) {
indexes.add(i);
}
}
return indexes;
}

private void removeEmptyGroupsAndChildren(List indexes, List groups,
List children) {
for (int i = 0; i < indexes.size(); i++) {
groups.remove(indexes.get(i));
children.remove(indexes.get(i));
}
}

@Override
public boolean onChildClick(android.widget.ExpandableListView parent,
View v, int groupPosition, int childPosition, long id) {
//Intent data = new Intent();
//data.putExtra("email", ((TextView) v).getText().toString());
//setResult(Activity.RESULT_OK, data);
//finish();
Toast.makeText(getApplicationContext(), ((TextView) v).getText().toString(), 12).show();
return true;
}
}
jessmalade
Freshman
Freshman
 
Posts: 3
Joined: Mon Nov 09, 2009 12:38 pm

Re: im beggin u help me

Postby Rashi » Sat Jun 05, 2010 12:11 pm

Hi jessmalade ur code is very nice and thanks a ton for it. :)

Thanks again
Rashi
Rashi
Developer
Developer
 
Posts: 32
Joined: Thu Sep 10, 2009 11:28 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 22 guests