get Profile from Context - Android android.provider

Android examples for android.provider:ContactsContract

Description

get Profile from Context

Demo Code


//package com.java2s;

import android.annotation.TargetApi;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
import android.provider.ContactsContract;

public class Main {
    @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
    public static Cursor getProfile(Context context) {
        // From http://stackoverflow.com/a/2175688/1339200
        if (context == null) {
            return null;
        }//w  w  w  .  ja v  a 2 s.c o  m
        Uri uri = Uri.withAppendedPath(
                ContactsContract.Profile.CONTENT_URI,
                ContactsContract.Contacts.Data.CONTENT_DIRECTORY);
        return context.getContentResolver().query(uri, null, null, null,
                ContactsContract.Contacts.Data.IS_PRIMARY + " DESC");
    }
}

Related Tutorials