package com.~.intent;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// ์ฐ๋ฝ์ฒ ์ ํํ๋ ์กํฐ๋นํฐ ๋์ฐ๊ธฐ
// selectContact();
// ์น ๋ธ๋ผ์ฐ์ ์กํฐ๋นํฐ๋ฅผ ์คํ์ํค๋ ํจ์
// openWebPage("http://naver.com");
// SMS ์์ฑํ๋ ์กํฐ๋นํฐ๋ฅผ ์คํ์ํค๋ ํจ์
// composeSMS("010-2222-3333");
// ์ด๋ฉ์ผ ์์ฑํ๋ ์กํฐ๋นํฐ๋ฅผ ์คํ์ํค๋ ํจ์
// composeEmail(new String[]{"abc@naver.com"},"์ด๋ฉ์ผ ์ ๋ชฉ");
// ๊ณต์ ๋ฒํผ ๋๋ฌ์, ๋ฌธ์์ด์ ๊ณต์ ํ ์ ์๋๋ก ํ๋ ํจ์
// shareText("์๋
ํ์ธ์~~");
}
});
}
// ์ฐ๋ฝ์ฒ ์ ํํ๋ ์กํฐ๋นํฐ ๋์ฐ๊ธฐ
void selectContact(){
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
startActivity(intent);
}
// ์น ๋ธ๋ผ์ฐ์ ์กํฐ๋นํฐ๋ฅผ ์คํ์ํค๋ ํจ์
void openWebPage(String urI){
Uri uri = Uri.parse(urI);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
// SMS ์์ฑํ๋ ์กํฐ๋นํฐ๋ฅผ ์คํ์ํค๋ ํจ์
void composeSMS(String phone){
Uri uri = Uri.parse("smsto:" + phone);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
// ์ด๋ฉ์ผ ์์ฑํ๋ ์กํฐ๋นํฐ๋ฅผ ์คํ์ํค๋ ํจ์
void composeEmail(String[] address, String subject){
Uri uri = Uri.parse("mailto:");
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(uri);
intent.putExtra(Intent.EXTRA_EMAIL, address);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
startActivity(intent);
}
// ๊ณต์ ๋ฒํผ ๋๋ฌ์, ๋ฌธ์์ด์ ๊ณต์ ํ ์ ์๋๋ก ํ๋ ํจ์
void shareText(String text){
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, text);
intent.setType("text/plain");
Intent shareIntent = Intent.createChooser(intent, "์ ํํ์ธ์");
startActivity(shareIntent);
}
}