package com.example.forseveralactivity;
import androidx.appcompat.app.AppCompatActivity;
import android.app.SearchManager;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
//직풀: 투표결과, 화면에서 가장 많은 표를 받은 그림과 제목을 보여줌
//result.xml(second.xml)과 ResultActivity.java만을 수정
//이미지파일의 id를 저장할 배열을 만들고, 레이팅바를 작게 변경
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setTitle("암시적 인텐트 예제");
Button btnDial = (Button) findViewById(R.id.btnDial);
Button btnSearch = (Button) findViewById(R.id.btnSearch);
Button btnSms = (Button) findViewById(R.id.btnSms);
Button btnGooolge = (Button) findViewById(R.id.btnGoolge);
Button btnWeb = (Button) findViewById(R.id.btnWeb);
Button btnPhoto = (Button) findViewById(R.id.btnPhoto);
btnDial.setOnClickListener(new View.OnClickListener() {
@Override
//전화 걸기 위해, Uri문자열을 tel:전화번호 형식으로 사용
//ACTION_DIAL: 전화걸기 창이 열림
public void onClick(View view) {
Uri uri= Uri.parse("tel:01012345678");
Intent intent=new Intent(Intent.ACTION_DIAL, uri);
startActivity(intent);
}
});
btnWeb.setOnClickListener(new View.OnClickListener() {
@Override
//웹브라우저 걸기 위해, Uri문자열을 웹주소 형식으로 사용
//ACTION_VIEW:특정 사이트를 뷰함
public void onClick(View view) {
Uri uri= Uri.parse("http://hanbit.co.kr");
Intent intent=new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
});
btnSms.setOnClickListener(new View.OnClickListener() {
@Override
//문자 보내기 위해, ACTION_SENDTO.
// 보낼 문자는 putExtra()로 넘기는데, 첫번째 파라미터에 "sms_body"를,
//두번째 파라미터에 보낼 문자의 내용을 넣고
//setData()설정이 필수
public void onClick(View view) {
Intent intent=new Intent(Intent.ACTION_SENDTO);
intent.putExtra("sms_body", "안녕하세요?");
intent.setData(Uri.parse("sms to:"+Uri.encode("010-1234-5678")));
startActivity(intent);
}
});
btnSearch.setOnClickListener(new View.OnClickListener() {
@Override
//검색 내용을 putextra로 넘김. 첫번째 파라미터는 SearchManager.QUERY
//ACTION_WEB_SEARCH: 구글검색 열기
public void onClick(View view) {
Intent intent=new Intent(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY, "안드로이드");
startActivity(intent);
}
});
btnPhoto.setOnClickListener(new View.OnClickListener() {
@Override
//카메라 열기 위한 액션 MediaStore.ACTION_IMAGE_CAPTURE
public void onClick(View view) {
Intent intent=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivity(intent);
}
});
btnGooolge.setOnClickListener(new View.OnClickListener() {
@Override
//uri문자열은 구글맵주소, 경위도 형식
//ACTION_VIEW:해당 사이트를 뷰
public void onClick(View view) {
Uri uri= Uri.parse("http://maps.google.com/maps?q="+
37.559133+","+126.927814);
Intent intent=new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
});
}
}
////////////////////
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="전화 걸기"
android:id="@+id/btnDial"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="홈페이지 열기"
android:id="@+id/btnWeb"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="구글앱 열기"
android:id="@+id/btnGoolge"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="구글 검색"
android:id="@+id/btnSearch"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="메세지 보내기"
android:id="@+id/btnSms"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="사진찍기"
android:id="@+id/btnPhoto"/>
</LinearLayout>
'동방프로젝트' 카테고리의 다른 글
실습11-1)그리드뷰 (0) | 2020.08.19 |
---|---|
리스트뷰 (2) | 2020.08.19 |
직풀 10-3 (2) | 2020.08.19 |
실습 10-2, 직풀 10-2 (0) | 2020.08.18 |
직풀 10-1 (0) | 2020.08.17 |