Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
// Licensed to the Apache Software Foundation (ASF) under one

import java.util.ArrayList;

import android.content.Context;

import android.database.Cursor;

import android.provider.ContactsContract.CommonDataKinds.Phone;

import android.util.Log;

public class Main {
    private static ArrayList<String> getNumbers(Context context) {
        ArrayList<String> list = new ArrayList<String>();
        Cursor cursor = null;
        try {
            cursor = context.getContentResolver().query(Phone.CONTENT_URI, null, null, null, null);
            int phoneNumberIdx = cursor.getColumnIndex(Phone.NUMBER);
            cursor.moveToFirst();
            do {
                String phoneNumber = cursor.getString(phoneNumberIdx);
                list.add(phoneNumber);
            } while (cursor.moveToNext());
        } catch (Exception e) {
            Log.d(context.getPackageName(), e.toString());
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }

        return list;
    }
}