[TIL]221019 - Kotlin Explicit Intent 실습

Jimin·2022년 10월 19일
0
post-custom-banner

Implicit Intent 실습(2)

  1. 주소로 검색

  2. 좌표로 검색 + zoom 설정

  3. 전화걸기

  4. sms 보내기

 binding.btnMap.setOnClickListener{
            val uri = Uri.parse("geo:36.145014, 128.393047?z=17")
            val intent = Intent(Intent.ACTION_VIEW, uri)
            startActivity(intent)
        }
        binding.btnTelephone.setOnClickListener {
            val uri = Uri.parse("sms:010-1234-5678")
                val intent = Intent(Intent.ACTION_VIEW, uri)
            startActivity(intent)
        }

Explicit Intent 실습

  1. Toast 사용
Toast.makeText(this, "눌렸습니다",
Toast.LENGTH_SHORT).show() 
//static 메소드를 사용했으므로 show를 반드시 호출 해줘야 함!!
  • 새로운 Activity 생성

문제가 생긴다? androidManifest 다시 확인해보기

  • 유튜브 열기

  • 검색어 입력 후 유튜브에서 열기

        binding.btnExplicitIntent.setOnClickListener {
            val intent = Intent(this, ImageActivity::class.java)
            startActivity(intent)
        }

        binding.btnImplicitIntent.setOnClickListener {
            val uri = Uri.parse("https://www.youtube.com/results?search_query=" + binding.editText.text)
            val intent = Intent(Intent.ACTION_VIEW, uri)
            startActivity(intent)
        }
//activity_main.xml


    <Button
        android:id="@+id/btn_explicit_intent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="이미지"
        app:layout_constraintBottom_toTopOf="@id/edit_text"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <EditText
        android:id="@+id/edit_text"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@id/btn_implicit_intent"
        app:layout_constraintTop_toBottomOf="@id/btn_explicit_intent"
        />
    <Button
        android:id="@+id/btn_implicit_intent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        android:text="유튜브"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toRightOf="@id/edit_text"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@id/btn_explicit_intent" />
post-custom-banner

0개의 댓글