0

In Android contacts there is an account with name "ME" in the head of the contact list where i put all my personal information, how can i get these information in my App , i can get the email account from the accounts by this

Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+
Account[] accounts = AccountManager.get(context).getAccounts();
for (Account account : accounts) {
    if (emailPattern.matcher(account.name).matches()) {
        String possibleEmail = account.name;
        ...
    }
}

but in my app i need all the available data like name , mobile number, home number, email. so is there a way to do this ?

Mothana
  • 41
  • 10
  • http://stackoverflow.com/questions/2112965/how-to-get-the-android-devices-primary-e-mail-address/2175688#2175688 – Swayam Dec 18 '13 at 11:22
  • Swayam, this article talks about getting the accounts in the phone i want the data from the "ME" contact m but thanks :) – Mothana Dec 18 '13 at 11:34
  • Yes , see the link above with some change you will get ME Data , change is in the answer below .... – Mothana Mar 06 '14 at 07:42

1 Answers1

1
public Loader<Cursor> onCreateLoader(int id, Bundle arguments) {
        return new CursorLoader(this,
                // Retrieve data rows for the device user's 'profile' contact.
                Uri.withAppendedPath( ContactsContract.Profile.CONTENT_URI,ContactsContract.Contacts.Data.CONTENT_DIRECTORY),
                ProfileQuery.PROJECTION,

                //Don't select anything here null will return all available fields

                null,
                null,                   
                null);
    }
    @Override
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
        ArrayList<String> DataArray = new ArrayList<String>();
        cursor.moveToFirst();
        while (!cursor.isAfterLast()) {
                    //here where you get your data and its type
            TypeName=cursor.getString(ProfileQuery.ADDRESS);//this will give you field name
            Data=cursor.getString(ProfileQuery.NUMBER);//this will give you field data

            cursor.moveToNext();
        }
    }
    @Override
public void onLoaderReset(Loader<Cursor> cursorLoader) {
    }
private interface ProfileQuery {
        String[] PROJECTION = {
                ContactsContract.Contacts.Data.MIMETYPE,
                ContactsContract.CommonDataKinds.Email.ADDRESS  ,
                ContactsContract.CommonDataKinds.Email.DISPLAY_NAME,
                ContactsContract.CommonDataKinds.Organization.DATA3,

        };

        int ADDRESS = 0;
        int NUMBER = 1;
    }

EDITED :

in this link How to get the Android device's primary e-mail address

in onCreateLoader he specify the Email only so just remove this and modify the interface and you will get the result you want

Community
  • 1
  • 1
Mothana
  • 41
  • 10