728x90
반응형
위 이미지처럼 특정 기능을 사용하는 앱을 실행할때 원하는 앱을 선택해본 경험이 있을겁니다.
지도, 메일보내기, 웹브라우저 실행등 예시들이 더 있겠네요.
구현방법은 간단합니다.
protected fun moveToStore() {
// Google Play Store로 이동하는 Intent 생성
val playStoreIntent = Intent(Intent.ACTION_VIEW).apply {
data = Uri.parse("http://play.google.com/store/apps/details?id=${BuildConfig.APPLICATION_ID}")
}
// One Store로 이동하는 Intent 생성
val oneStoreIntent = Intent(Intent.ACTION_VIEW).apply {
data = Uri.parse("onestore://common/product/${BuildConfig.ONE_STORE_PID}")
}
// Intent 리스트 생성
val intents = ArrayList<Intent>().apply {
add(playStoreIntent)
add(oneStoreIntent)
}
// Intent Chooser 생성
val chooserIntent = Intent.createChooser(Intent(), "Select Store").apply {
putExtra(Intent.EXTRA_INITIAL_INTENTS, intents.toTypedArray())
}
// Chooser 실행
startActivity(chooserIntent)
}
간단하죠?
사용하고 싶은 Intent들을 ArrayList로 만들어서 createChooser함수에게 전달하면 됩니다.
728x90
반응형
'Programming > Kotlin' 카테고리의 다른 글
[Kotlin] NestedScrollView 안에 여백 생길경우 (0) | 2023.05.08 |
---|---|
[kotlin] view pager 2 높이 조정(wrap_content) (0) | 2023.04.10 |
코틀린 Retrofit2 Response 반환값 null 인경우 (1) | 2023.02.09 |
CollapsingToolbarLayout 와 Viewpager2 호환문제 (0) | 2023.02.03 |
[코틀린] constraint 속성 동적으로 추가 (0) | 2022.08.22 |