Android Contact Get getOperatorByNumber( ContentResolver contentResolver, String number)

Here you can find the source of getOperatorByNumber( ContentResolver contentResolver, String number)

Description

get Operator By Number

Declaration

public static String getOperatorByNumber(
            ContentResolver contentResolver, String number) 

Method Source Code

//package com.java2s;
import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract;
import android.provider.ContactsContract.PhoneLookup;

public class Main {
    public static String getOperatorByNumber(
            ContentResolver contentResolver, String number) {
        Uri uri = Uri.withAppendedPath(//  ww  w .  j  a v  a 2  s  . co m
                ContactsContract.PhoneLookup.CONTENT_FILTER_URI,
                Uri.encode(number));

        Cursor contactLookup = contentResolver.query(uri,
                new String[] { PhoneLookup.LABEL }, null, null, null);

        try {
            if (contactLookup != null && contactLookup.getCount() > 0) {
                while (contactLookup.moveToNext()) {
                    String operator = contactLookup.getString(contactLookup
                            .getColumnIndexOrThrow(PhoneLookup.LABEL));

                    if (operator != null) {
                        return operator;
                    }
                }

            }
        } catch (Exception e) {
            return null;
        } finally {
            if (contactLookup != null) {
                contactLookup.close();
            }
        }

        return null;
    }
}

Related

  1. getEmail(int contactId)