Tip/Android2023. 8. 22. 23:34

AndroidManifest.xml에 아래와 같이 권한을 추가 한다

    <uses-feature
        android:name="android.hardware.telephony"
        android:required="false" />

    <uses-feature android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.CALL_PHONE" />

 MainActivity안에 아래와 같이 버튼에 이벤트를 연결한다.

    private fun init() {
        val callButton : Button = findViewById(R.id.callButton)
        callButton.setOnClickListener( View.OnClickListener { _ -> runCall() })
    }

    private fun runCall() {
        val intent = Intent(Intent.ACTION_CALL, Uri.parse("tel:01234561492"))
        val status = ActivityCompat.checkSelfPermission(this, 
            android.Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_GRANTED
        if (status) {
            startActivity(intent)
        } else {
            Log.i("TAG", "Unable to launch call");
            ActivityCompat.requestPermissions(this, 
                arrayOf<String>(android.Manifest.permission.CALL_PHONE), CALL_REQUEST)
        }
    }

아래와 같이 onRequestPermissionsReseult()를 오버라이딩 해주면, 권한 컨펌 즉시 콜이 걸리게 된다.

    override fun onRequestPermissionsResult(
        requestCode: Int,
        permissions: Array<out String>,
        grantResults: IntArray
    ) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults)
        when (requestCode) {
            CALL_REQUEST -> {
                if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    Toast.makeText(this, "통화가 가능 합니다", Toast.LENGTH_LONG).show()
                    runCall()
                } else {
                    Toast.makeText(this, "통화가 거절 되었습니다", Toast.LENGTH_LONG).show()
                }
            }
        }
    }
Posted by chobocho
Coding/Java 삽질기2018. 8. 15. 16:36

목표 : 아래 이미지와 같은 앱을 만든다


소스코드 : https://github.com/chobocho/Triangle

Play store: https://play.google.com/store/apps/details?id=com.chobocho.triangle



Posted by chobocho
Coding/JVM 삽질기2017. 10. 14. 02:13
1. sdkman 설치

curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh”

2. Java와 Kotlin 설치 
sdk install java
sdk install kotlin

3. Kotlin 으로 helloworld.kt  만들기

fun main(args: Array<String>) { 
    println("Hello, World!!”)
}


4. Compile helloworld.kt
kotlinc helloworld.kt -include-runtime -d helloworld.jar

5. 실행하기
java -jar helloworld.jar

* Reference

http://sdkman.io/install.html

https://kotlinlang.org/docs/tutorials/command-line.html



'Coding > JVM 삽질기' 카테고리의 다른 글

[groovy] 50!  (0) 2016.09.24
Groovy 설치( Mac )  (0) 2014.11.11
Pocket PC를 위한 JVM  (0) 2005.09.28
Posted by chobocho