Intent로 SMS, MMS, Mail 보내기



java)

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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package ghj.com.messageintent;
 
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
 
public class MainActivity extends AppCompatActivity {
 
    EditText editBody;
 
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
 
        editBody = (EditText)findViewById(R.id.editBody);
        Button btnSms = (Button)findViewById(R.id.btnSms);
        btnSms.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                sendSmsIntent("010-1234-1234");
            }
        });
 
        Button btnMms = (Button)findViewById(R.id.btnMms);
        btnMms.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getImage();
            }
        });
 
        Button btnEmail = (Button)findViewById(R.id.btnEmail);
        btnEmail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sendEmail("ghj@naver.com");
            }
        });
    }
 
 
    public void sendSmsIntent(String number){
        try{
            Uri smsUri = Uri.parse("sms:"+number);
            Intent sendIntent = new Intent(Intent.ACTION_SENDTO, smsUri);
            sendIntent.putExtra("sms_body", editBody.getText().toString());
            startActivity(sendIntent);
 
//        Intent sendIntent = new Intent(Intent.ACTION_VIEW);
//        sendIntent.putExtra("address", number);
//        sendIntent.putExtra("sms_body", editBody.getText().toString());
//        sendIntent.setType("vnd.android-dir/mms-sms");
//        startActivity(sendIntent);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
 
    public void sendMmsIntent(String number, Uri imgUri){
        try{
            Intent sendIntent = new Intent(Intent.ACTION_SEND);
            sendIntent.putExtra("address", number);
            sendIntent.putExtra("subject""MMS Test");
            sendIntent.putExtra("sms_body", editBody.getText().toString());
            sendIntent.setType("image/*");
            sendIntent.putExtra(Intent.EXTRA_STREAM, imgUri);
            startActivity(Intent.createChooser(sendIntent, getResources().getString(R.string.app_name)));
        }catch (Exception e){
            e.printStackTrace();
        }
    }
 
    public void getImage(){
        try{
            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            intent.setType("image/*");
            startActivityForResult(Intent.createChooser(intent, "Image Choose"), 1);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
 
    public void sendEmail(String email){
        try{
            Intent emailIntent = new Intent(Intent.ACTION_SEND);
            emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{email});
            emailIntent.putExtra(Intent.EXTRA_CC, new String[]{email});
            emailIntent.putExtra(Intent.EXTRA_BCC, new String[]{email});
            emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Email Test");
            emailIntent.putExtra(Intent.EXTRA_TEXT, editBody.getText().toString());
            emailIntent.setType("message/rfc822");
            startActivity(Intent.createChooser(emailIntent, "Email Choose"));
        }catch (Exception e){
            e.printStackTrace();
        }
    }
 
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if(requestCode == 1){
            if(resultCode==RESULT_OK){
                Uri imgUri = data.getData();
 
                sendMmsIntent("010-1234-1234", imgUri);
            }
        }
    }
}
 
cs



xml)

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
<?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"
    android:orientation="vertical"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="ghj.com.messageintent.MainActivity">
 
    <EditText
        android:id="@+id/editBody"
        android:layout_width="match_parent"
        android:layout_height="50dp" />
 
 
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <Button
            android:id="@+id/btnSms"
            android:text="SMS 인텐트"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
 
        <Button
            android:id="@+id/btnMms"
            android:text="MMS 인텐트"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
 
        <Button
            android:id="@+id/btnEmail"
            android:text="Email"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>
 
 
</LinearLayout>
 
cs



결과

svg 의 텍스트에 링크걸기



html)

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
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" 
          content="width=device-width, height=device-height, 
                     minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0">
    <title>Insert title here</title>
</head>
 
<body>
    <?xml version="1.0" ?>
    <svg xmlns="http://www.w3.org/2000/svg" width="300px" height="400px" version="1.1">
        <!-- 
        a : 외부링크 연결하기
            xlink:href=사이트주소
            target="_blank" : 새창에서 열기
         -->
        <a xlink:href="http://www.naver.com" target="_blank">
            <text x="50" y="50" font-size="30px" font-weight="bold" style="fill:green;">
            NAVER
            </text>
        </a>
        <a xlink:href="http://www.google.com" target="_blank">
            <text x="50" y="100" font-size="30px" font-weight="bold" style="fill:blue;">
            GOOGLE
            </text>
        </a>
    </svg>
</body>
</html>
cs



결과

svg 의 path 따라서 텍스트 나타내기



html)

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
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" 
          content="width=device-width, height=device-height, 
                     minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0">
    <title>Insert title here</title>
</head>
 
<body>
    <?xml version="1.0" ?>
    <svg xmlns="http://www.w3.org/2000/svg" width="300px" height="400px" version="1.1">
        <!-- path 를 미리 정의합니다. -->
        <defs>
            <path id="path" d="M50,100 C100,0 150,200 200,100" />
        </defs>
 
        <!-- textPath : 텍스트가 그려질 path 를 지정합니다. -->    
        <text font-size="15px" font-weight="bold" style="fill:green;">
            <textPath xlink:href="#path">선따라 텍스트를 그립니다...</textPath>
        </text>
    </svg>
</body>
</html>
cs



결과

svg의 defs 요소 : 참조를 위한 컨테이너



html)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" 
          content="width=device-width, height=device-height, 
                     minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0">
    <title>Insert title here</title>
</head>
 
<body>
    <?xml version="1.0" ?>
    <svg xmlns="http://www.w3.org/2000/svg" width="300px" height="400px" version="1.1">
        <!-- defs : 내용을 미리 정의해 놓는다 -->
        <defs>
            <rect id="test" x="50" y="50" rx="10" ry="10" width="100" height="100" /
        </defs>
        
        <!-- 일치하는 id 값의 내용을 보여준다 -->
        <use xlink:href="#test" />
    </svg>
</body>
</html>
cs



결과

svg 로 글자쓰기



html)

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
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" 
          content="width=device-width, height=device-height, 
                     minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0">
    <title>Insert title here</title>
</head>
 
<body>
    <?xml version="1.0" ?>
    <svg xmlns="http://www.w3.org/2000/svg" width="300px" height="400px" version="1.1">
        <!-- 
        x : 텍스트가 쓰여질 x좌표
        y : 텍스트가 쓰여질 y좌표
        font-family : 폰트종료
        font-size : 폰트크기
        font-weight : 폰트스타일
        fill : 글자색
         -->
        <text x="50" y="50" font-family="sans-serif" font-size="30px" font-weight="bold"
              style="fill:green;opacity:0.5;">Hello World!</text>
    </svg>
</body>
</html>
cs



결과

svg 로 path 요소로 선긋기



대문자는 절대좌표, 소문자는 상대좌표

M, m

시작점 지정

L, l 

직선 그리기 

Z, z

시작점까지 연결하기 

H, h 

수평선 긋기 

V, v

수직선 긋기

C, c 

곡선 긋기 

S, s

곡선 이어긋기 

Q, q 

2차원 베지어 곡선 긋기

T, t 

2차원 베지어 곡선 이어긋기 

A, a 

타원이나 호 그리기 



html)

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
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" 
          content="width=device-width, height=device-height, 
                     minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0">
    <title>Insert title here</title>
</head>
 
<body>
    <?xml version="1.0" ?>
    <svg xmlns="http://www.w3.org/2000/svg" width="300px" height="400px" version="1.1">
        <!-- 직선 그리기 -->
        <!-- Lx좌표,y좌표 -->
        <path d="M50,50 L200,50 200,100Z" 
              stroke="green" stroke-width="5" fill="none" />
              
        <!-- 수평선 긋기 -->
        <!-- Hx좌표 -->
        <path d="M50,150 H200"
              stroke="green" stroke-width="5" />
              
        <!-- 수직선 긋기 -->
        <!-- Vy좌표 -->
        <path d="M250,50 V150"
              stroke="green" stroke-width="5" />
 
        <!-- 곡선 긋기 -->
        <!-- C조절점1x,조절점1y 조절점2x,조절점2y 끝점x,끝점y -->
        <path d="M50,200 C100,250 150,150 200,200" 
              stroke="green" stroke-width="5" fill="none" />
              
        <!-- 곡선 이어긋기 -->
        <!-- S조절점x,조절점y 끝점x,끝점y -->
        <!-- 시작지점은 이전 곡선의 마지막 조절점의 반태편 또는 곡선이 없을 경우 마지막 지점이다 -->
        <path d="M50,250 C100,300 150,200 200,250 S250,200 300,250"
              stroke="green" stroke-width="5" fill="none" />
              
        <!-- 2차원 베지어 곡선 그리기 -->
        <!-- Q조절점x,조절점y 끝점x,끝점y -->
        <path d="M50,300 Q125,350 200,300" 
              stroke="green" stroke-width="5" fill="none" />
            
        <!-- 베지어 곡선 이어긋기 -->
        <!-- T끝점x,끝점y -->
          <!-- 시작지점은 이전 곡선의 마지막 조절점의 반태편 또는 곡선이 없을 경우 마지막 지점이다 -->
        <path d="M50,350 Q125,400 200,350 T300,350"
              stroke="green" stroke-width="5" fill="none" />
    </svg>
</body>
</html>
cs



결과

svg 로 다각형 그리기



html)

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
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" 
          content="width=device-width, height=device-height, 
                     minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0">
    <title>Insert title here</title>
</head>
 
<body>
    <?xml version="1.0" ?>
    <svg xmlns="http://www.w3.org/2000/svg" width="300px" height="400px" version="1.1">
        <!-- 
        polygon : 선의 끝부분이 연결된다
            points : 띄어쓰기로 점들을 지정한다
         -->    
        <polygon points="50,50 200,50 250,100 200,150 50,150" 
                 style="fill:orange; stroke:green; stroke-width:5;" />
        
        <!-- 
        polyline : 선의 끝부분이 연결되지 않는다         
            points : 띄어쓰기로 점들을 지정한다
         -->
        <polyline points="50,200 200,200 250,250 200,300 50,300" 
                 style="fill:orange; stroke:green; stroke-width:5;" />
    </svg>
</body>
</html>
cs



결과

'IT > - 프로그래밍' 카테고리의 다른 글

HTML5/CSS3 svg 로 글자쓰기  (0) 2017.07.22
HTML5/CSS3 svg 로 path 요소로 선긋기  (0) 2017.07.21
HTML5/CSS3 svg 로 선그리기  (0) 2017.07.19
HTML5/CSS3 svg 로 타원 그리기  (0) 2017.07.18
HTML5/CSS3 svg 로 원 그리기  (0) 2017.07.17

svg 로 선그리기



html)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Insert title here</title>
</head>
 
<body>
    <?xml version="1.0" ?>
    <svg xmlns="http://www.w3.org/2000/svg" width="300px" height="400px" version="1.1">
        <!-- 
        x1 : 시작점 x좌표
        y1 : 시작점 y좌표
        x2 : 끝점 x좌표
        y2 : 끝점 y좌표
         -->
        <line x1="50" y1="100" x2="250" y2="100"
              style="stroke:green; stroke-width:5; stroke-opacity:0.5;" />
    </svg>
</body>
</html>
cs



결과

svg 로 타원 그리기



html)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" 
          content="width=device-width, height=device-height, 
                     minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0">
    <title>Insert title here</title>
</head>
 
<body>
    <?xml version="1.0" ?>
    <svg xmlns="http://www.w3.org/2000/svg" width="300px" height="400px" version="1.1">
        <!-- 
        cx : 중점 x좌표
        cy : 중점 y좌표
        rx : 가로 반지름 크기
        ry : 세로 반지름 크기
         -->
        <ellipse cx="100" cy="100" rx="75" ry="50"
                 style="fill:orange; stroke:green; stroke-width:3;" />
    </svg>
</body>
</html>
cs



결과

svg 로 원 그리기



html)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" 
          content="width=device-width, height=device-height, 
                     minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0">
    <title>Insert title here</title>
</head>
 
<body>
    <?xml version="1.0"?>
    <svg xmlns="http://www.w3.org/2000/svg" width="300px" height="400px" version="1.1">
        <!-- 
        circle : 원
            cx : 중심점 x
            cy : 중심점 y
            r : 반지름
        -->
        <circle cx="150" cy="150" r="100" 
                style="fill:orange; stroke:#000; stroke-width:3;" />
    </svg>
</body>
</html>
cs



결과

+ Recent posts