3일이나 걸렷네요
=========================================================================================
package com.example.getcontract;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.Locale;
import java.util.TimeZone;
import android.net.Uri;
import android.os.Bundle;
import android.provider.CallLog;
import android.provider.ContactsContract;
import android.provider.ContactsContract.Contacts;
import android.app.Activity;
import android.app.ListActivity;
import android.database.Cursor;
import android.util.Log;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class MainActivity extends ListActivity {
String tag = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
Cursor cursor = getURI(); // 전화번호부 가져오기
int end = cursor.getCount(); // 전화번호부의 갯수 세기
Log.d(tag, "end = "+end);
String [] name = new String[end]; // 전화번호부의 이름을 저장할 배열 선언
String [] dTime = new String[end];
long [] intDTime= new long[end];
int count = 0;
if(cursor.moveToFirst())
{
// 컬럼명으로 컬럼 인덱스 찾기
int idIndex = cursor.getColumnIndex("_id");
do
{
// 요소값 얻기
int id = cursor.getInt(idIndex);
intDTime[count] = cursor.getInt(idIndex);
name[count] = cursor.getString(1);
int dateColumn = cursor.getColumnIndex(CallLog.Calls.DATE);
long callDate = cursor.getLong(dateColumn);
SimpleDateFormat formatter = new SimpleDateFormat ( "yyyy-MM-dd HH:mm:ss ", Locale.KOREA );
String date_str = formatter.format(new Date(callDate));
dTime [count] = date_str;
// LogCat에 로그 남기기
Log.d(tag, "id=" + id +", name["+count+"]=" + name[count]);
count++;
} while(cursor.moveToNext() || count > end);
}
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_single_choice, dTime));
final ListView listView = getListView();
listView.setItemsCanFocus(false);
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
}
private Cursor getURI()
{
// 주소록 URI
// Uri people = Contacts.CONTENT_URI;
Uri people = CallLog.Calls.CONTENT_URI;
// 검색할 컬럼 정하기
String[] projection = new String[] {CallLog.Calls._ID, CallLog.Calls.CACHED_NAME, CallLog.Calls.DATE}; // { Contacts._ID, Contacts.DISPLAY_NAME, Contacts.HAS_PHONE_NUMBER };
String selection = null;//ContactsContract.Contacts.DISPLAY_NAME + " >= 'ㄱ' and "+ContactsContract.Contacts.DISPLAY_NAME + " <= 'ㄷ' ";
// 쿼리 날려서 커서 얻기
String[] selectionArgs = null;
String sortOrder = CallLog.Calls.DEFAULT_SORT_ORDER;//ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
return managedQuery(people, projection, selection, selectionArgs, sortOrder);
}
}