외부프로그램과 연결

- 브라우저 : 네이버

- 전화걸기 화면 이동

- 구글 검색화면 이동

- 전화번호부로 이동

 

 

아래 화면으로 이동.

 

 

 

(1) activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <Button
        android:id="@+id/btn1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="네이버로이동" />

    <Button
        android:id="@+id/btn2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="전화번호부" />

    <Button
        android:id="@+id/btn3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="전화걸기" />

    <Button
        android:id="@+id/btn4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="검색하기" />

</LinearLayout>

 

 

 

(2) MainActivity.java

인텐트
 - 명시적인텐트 : 호출할 대상 컴포넌트가 분명히 명시되어 있는 인텐트(클래스)
 - 암시적 인텐트: 호출대상이 분명히 정해지지 않은 인텐트(안드로이드가 분석해서 해당 작업을 수행할 액티비티를 호출한다.)

 

package com.example.test22_intentaction;

import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.app.Activity;
import android.app.SearchManager;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;

 

public class MainActivity extends Activity implements OnClickListener{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       
        findViewById(R.id.btn1).setOnClickListener(this);
        findViewById(R.id.btn2).setOnClickListener(this);
        findViewById(R.id.btn3).setOnClickListener(this);
        findViewById(R.id.btn4).setOnClickListener(this);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    @Override
    public void onClick(View v) {

        switch(v.getId()){

        case R.id.btn1:
            Intent intent=new Intent();
            //액션지정하기
            intent.setAction(Intent.ACTION_VIEW);
            //보여줄 정보지정(무엇을 보여줄건지를 url로 설정)
            intent.setData(Uri.parse("http://www.naver.com"));
            startActivity(intent);
            break;

       

       // 전화걸기
        case R.id.btn2:           
            Intent intent1=new Intent();
            //액션지정
            intent1.setAction(Intent.ACTION_VIEW);
            //보여줄 정보 지정
            intent1.setData(ContactsContract.Contacts.CONTENT_URI);
            startActivity(intent1);
            break;

 

      case R.id.btn3:
            Intent intent2 = new Intent();
            intent2.setAction(Intent.ACTION_DIAL);
            intent2.setData(Uri.parse("tel:010-111-1234"));
            startActivity(intent2);
            break;

 

       case R.id.btn4:
            Intent intent3 = new Intent();
            //호출액션
            intent3.setAction(Intent.ACTION_WEB_SEARCH);
            //검색단어 넣기
            intent3.putExtra(SearchManager.QUERY,"김연아");
            startActivity(intent3);
            break;
        }

    }
}

+ Recent posts