Android

Android - Intent

프리덕 2020. 9. 20. 21:06
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?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"
    tools:context=".MainActivity"
    android:orientation="vertical">
 
   <Button
       android:id="@+id/btnHomepage"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:backgroundTint="#5A5151"
       android:text="네이트 홈페이지 열기" />
 
   <Button
       android:id="@+id/btnCall"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:backgroundTint="#09DF2D"
       android:text="응급전화 걸기" />
 
   <Button
       android:id="@+id/btnGallery"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:backgroundTint="#EA0E0E"
       android:text="갤러리 열기" />
 
   <Button
       android:id="@+id/btnFinish"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:backgroundTint="#FFEB3B"
       android:text="끝내기" />
 
 
</LinearLayout>
 
//---------------------java code-----------------
package com.example.and0901_ch03_baseapp3;
 
import androidx.appcompat.app.AppCompatActivity;
 
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
 
public class MainActivity extends AppCompatActivity {
    Button btnHomepage,btnCall,btnGallery,btnFinish;
 
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        btnHomepage=findViewById(R.id.btnHomepage);
        btnCall=findViewById(R.id.btnCall);
        btnGallery=findViewById(R.id.btnGallery);
        btnFinish=findViewById(R.id.btnFinish);
 
        btnHomepage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.nate.com"));
                startActivity(intent);
            }
        });
 
        btnCall.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(Intent.ACTION_VIEW, Uri.parse("tel:/119"));
                startActivity(intent);
            }
        });
 
        btnGallery.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(Intent.ACTION_VIEW, Uri.parse("content://media/internal/images/media"));
                startActivity(intent);
            }
        });
 
        btnFinish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }
}
cs

 

클릭했을 때 인터넷 창을 열거나 전화 기능을 하게 한다 거나 사진첩을 열거나 하는 기능은 Intent라는 객체로 

기능이 사용가능하게 할 수 있다. Intent 란 일종의 비동기식 메시지 객체이다.
안드로이드 시스템으로 전달되어 시스템이 특정 구성 요소를 활성화할지 아니면 구성 요소의 특정 유형을 활성화할지를 나타내는 메시지객체이다. 사용하고자 하는 기능에 따라 조금씩 입력값을 바꿔가며 사용하면 된다.