본문 바로가기
App/Android Java

Android_Java(21) - ImplicitIntent

by SeleniumBindingProtein 2022. 2. 11.
728x90
반응형

1. 암시적 인텐트
    1) 어떤 작업을 하기 원하지만 그 작업을 담당하는 컴포넌트의 이름을 명확하게 모르는 경우에 사용   
    2) 인텐트의 형식(액션)
        - ACTION_VIEW : 데이터를 사용자에게 표시한다
        - ACTION_CALL : 전화 통화를 시작한다 
        - ACTION_DIAL : 전화 번호를 누르는 화면을 표시한다.
        ......
    3) 암시적인 인텐트 예
        - ACTION_VIEW
            - content://contacts/people/1 - 1번 연락처 정보를 표시한다. 
        - ACTION_DIAL
            - content://contacts/people/1 - 1번 연락처로 전화걸기 화면을 표시한다. 
    4) 약속된 액션(action)을 지정하여 안드로이드에서 제공하는 기존 응용프로그램을 실행하는 것

 


<MainActivity>

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/call"
        android:onClick="onClick"
        android:text="전화걸기"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/map"
        android:onClick="onClick"
        android:text="지도보기"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/web"
        android:onClick="onClick"
        android:text="웹브라우저"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/contact"
        android:onClick="onClick"
        android:text="연락처보기"/>

</LinearLayout>
package kr.co.implicitintent;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        getSupportActionBar().setIcon(R.drawable.ic_launcher);
    }
    public void onClick(View view){
        Intent intent = null;
        switch (view.getId()){
            case R.id.web:
                //액션이 ACTION_VIEW인 인텐트를 생성함. www.apple.com를 데이터로 설정함 
                // => 암시적 인텐트로 웹페이지를 봄
                intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.apple.com/"));
                break;
            case R.id.call:
            	//암시적 인텐트로 전화를 검
                intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel: (+82)025326509"));
                break;
            case R.id.map:
            	//암시적 인텐트로 지도를 봄
                intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:37.48660321,126.78315296"));
                break;
            case R.id.contact:
            	//암시적 인텐트로 연락처를 봄
                intent = new Intent(Intent.ACTION_VIEW, Uri.parse("content://contacts/people/"));
                break;
        }
        if(intent != null){
            //인텐트 시작함
            startActivity(intent);
        }
    }

}

 


[결과 출력]

01234

 

728x90
반응형

'App > Android Java' 카테고리의 다른 글

Android_Java(23) - MovieCustomListView  (0) 2022.02.13
Android_Java(22) - ActivityLifeCycle  (0) 2022.02.13
Android_Java(20) - MyIntent(3)  (0) 2022.02.11
Android_Java(19) - MyIntent(2)  (0) 2022.02.11
Android_Java(18) - MyIntent  (0) 2022.02.10

댓글