Notice
Recent Posts
Recent Comments
Link
«   2024/11   »
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
Archives
Today
Total
관리 메뉴

이곳저곳 관심이 많아요

10. Intent : Implicit intent 본문

Programming/Android

10. Intent : Implicit intent

킹수맨 2021. 11. 5. 14:05

1. MainActivity_기본

package com.example.myapplication

import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        findViewById<Button>(R.id.callButton).setOnClickListener {
            val intent = Intent(Intent.ACTION_DIAL, Uri.parse("tel:(+82)01012345678"))
            startActivity(intent)
        }
    }
}

2. MainActivity_let 사용

package com.example.myapplication

import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        findViewById<Button>(R.id.callButton).setOnClickListener {
            val intent = Uri.parse("tel:(+82)01012345678").let{ number->
                Intent(Intent.ACTION_DIAL, number)
            }
            startActivity(intent)
        }
    }
}
Comments