본문 바로가기

Android[Kotlin]

[Android][kotlin] intent 활용하여 링크로 사이트 연결, 전화연결

공식문서

textView.setOnClickListener {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://www.naver.com"))
startActivity(intent)                    
}

textView 클릭 시 네이버로 연결한다.

URL에 파라미터를 추가해서 넘기려면 URL 뒤에 붙여주도록 합니다.

textView.setOnClickListener {
String page = "/55"
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://https://lolou.tistory.com/$page"))
startActivity(intent)                    
}

 

전화연결

val shopPhone = "0507-1362-4318"
val intent = Intent(Intent.ACTION_DIAL)
// tel: 이걸 붙여줘야 인식함.
intent.data = Uri.parse("tel:$shopPhone")
startActivity(intent)
val intent = Intent(Intent.ACTION_DIAL, Uri.parse("tel:${shopPhone}"))