note

전화걸기2 컨텍트 프로바이더contact 본문

Android/기본

전화걸기2 컨텍트 프로바이더contact

투한 2012. 1. 17. 17:21







<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="vertical"
	android:layout_width="fill_parent"
	android:layout_height="fill_parent"
	>
	<Button android:id="@+id/pick"
		android:layout_width="fill_parent" 
		android:layout_height="fill_parent"
		android:layout_weight="1"
		android:text="선택"
	/>
	<Button android:id="@+id/view"
		android:layout_width="fill_parent" 
		android:layout_height="fill_parent"
		android:layout_weight="1"
		android:text="보기"
	/>
</LinearLayout>



package kr.android.intent4;
//컨택트 프로바이더 사용
import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.Button;

public class ContactDemo extends Activity {
	Button viewButton = null;
	Uri contact = null;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		Button btn= (Button)findViewById(R.id.pick);

		btn.setOnClickListener(new View.OnClickListener() {
			public void onClick(View view) {
				Intent i = new Intent(Intent.ACTION_PICK,
						Uri.parse("content://contacts/people"));
				startActivity(i);

			}
		});
		viewButton = (Button)findViewById(R.id.view);

		viewButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				startActivity(new Intent(Intent.ACTION_VIEW,
						Uri.parse("content://contacts/people/1")));
			}
		});
	}
}