Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.content.ContentResolver;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract;
import android.telephony.TelephonyManager;
import android.text.TextUtils;

public class Main {
    private static String[] CONTACT_PROJ = new String[] { "_id", "display_name", "normalized_number", "photo_uri",
            "photo_thumb_uri" };

    public static Cursor getOwnProfile(Context context) {
        return getContactProfile(context, getOwnNumber(context));
    }

    public static Cursor getContactProfile(Context context, String number) {
        if (TextUtils.isEmpty(number)) {
            return null;
        }

        ContentResolver cr = context.getContentResolver();
        Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));

        return cr.query(uri, CONTACT_PROJ, null, null, null);
    }

    public static String getOwnNumber(Context context) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        return tm.getLine1Number();
    }
}