네이버 내비게이션으로 넘어갈때 주소 넘겨받기
-
게시물 수정 , 삭제는 로그인 필요
private fun showAddressSearchDialog() {
val builder = AlertDialog.Builder(this)
val inflater = layoutInflater
val dialogView = inflater.inflate(R.layout.address_search_dialog, null)
builder.setView(dialogView)
val addressSearch = dialogView.findViewById<Button>(R.id.searchButton)
val addressText = dialogView.findViewById<EditText>(R.id.addressEditText)
addressSearch.setOnClickListener {
val address = addressText.text.toString()
if (address.isNotEmpty()) {
navigateToNaverNavigation(address)
addressDialog.dismiss()
} else {
Toast.makeText(this, "검색할 주소를 입력해주세요.", Toast.LENGTH_SHORT).show()
}
}
addressDialog = builder.create()
addressDialog.show()
}
private fun navigateToNaverNavigation(address: String) {
val encodedAddress = Uri.encode(address, "UTF-8")
val navigationUri = Uri.parse("navermaps://search?query=$encodedAddress")
val intent = Intent(Intent.ACTION_VIEW, navigationUri)
// intent.addCategory(Intent.CATEGORY_BROWSABLE)
val activities = packageManager.queryIntentActivities(intent, 0)
val isNavigationInstalled = activities.isNotEmpty()
if (isNavigationInstalled) {
try {
startActivity(intent)
} catch (e: ActivityNotFoundException) {
// 네비게이션 앱을 실행할 수 없는 경우에 대한 처리
Toast.makeText(
this,
"네비게이션 앱을 실행할 수 없습니다.",
Toast.LENGTH_SHORT
).show()
}
} else {
val alertDialogBuilder = AlertDialog.Builder(this)
.setTitle("네비게이션 앱이 설치되어 있지 않습니다.")
.setMessage("네비게이션 앱을 설치하시겠습니까?")
.setPositiveButton("설치") { _, _ ->
val marketIntent = Intent(
Intent.ACTION_VIEW,
Uri.parse("market://details?id=$NAVIGATION_PACKAGE")
)
// 설치할 수 있는 앱 마켓이 없는 경우에 대한 예외 처리
try {
startActivity(marketIntent)
} catch (e: ActivityNotFoundException) {
Toast.makeText(
this,
"앱 마켓을 찾을 수 없어 네비게이션 앱을 설치할 수 없습니다.",
Toast.LENGTH_SHORT
).show()
}
}
.setNegativeButton("취소") { _, _ ->
Toast.makeText(this, "네비게이션 앱을 설치하지 않았습니다.", Toast.LENGTH_SHORT).show()
}
.create()
alertDialogBuilder.show()
startActivity(intent)
}
주소를 검색하고 내비게이션으로 넘어갈때 주소가 내비 로 바로 가져가지게 하고 싶은데
아무리 노력해주 주소가 안넘어가지네요. ㅠ.ㅠ 흠
고수님들 도와 주시면 감사하겠습니다..
private fun showAddressSearchDialog() {
val builder = AlertDialog.Builder(this)
val inflater = layoutInflater
val dialogView = inflater.inflate(R.layout.address_search_dialog, null)
builder.setView(dialogView)
val addressSearch = dialogView.findViewById<Button>(R.id.searchButton)
val addressText = dialogView.findViewById<EditText>(R.id.addressEditText)
addressSearch.setOnClickListener {
val address = addressText.text.toString()
if (address.isNotEmpty()) {
navigateToNaverNavigation(address)
addressDialog.dismiss()
} else {
Toast.makeText(this, "검색할 주소를 입력해주세요.", Toast.LENGTH_SHORT).show()
}
}
addressDialog = builder.create()
addressDialog.show()
}
private fun navigateToNaverNavigation(address: String) {
val encodedAddress = Uri.encode(address, "UTF-8")
val navigationUri = Uri.parse("navermaps://search?query=$encodedAddress")
val intent = Intent(Intent.ACTION_VIEW, navigationUri)
// intent.addCategory(Intent.CATEGORY_BROWSABLE)
val activities = packageManager.queryIntentActivities(intent, 0)
val isNavigationInstalled = activities.isNotEmpty()
if (isNavigationInstalled) {
try {
startActivity(intent)
} catch (e: ActivityNotFoundException) {
// 네비게이션 앱을 실행할 수 없는 경우에 대한 처리
Toast.makeText(
this,
"네비게이션 앱을 실행할 수 없습니다.",
Toast.LENGTH_SHORT
).show()
}
} else {
val alertDialogBuilder = AlertDialog.Builder(this)
.setTitle("네비게이션 앱이 설치되어 있지 않습니다.")
.setMessage("네비게이션 앱을 설치하시겠습니까?")
.setPositiveButton("설치") { _, _ ->
val marketIntent = Intent(
Intent.ACTION_VIEW,
Uri.parse("market://details?id=$NAVIGATION_PACKAGE")
)
// 설치할 수 있는 앱 마켓이 없는 경우에 대한 예외 처리
try {
startActivity(marketIntent)
} catch (e: ActivityNotFoundException) {
Toast.makeText(
this,
"앱 마켓을 찾을 수 없어 네비게이션 앱을 설치할 수 없습니다.",
Toast.LENGTH_SHORT
).show()
}
}
.setNegativeButton("취소") { _, _ ->
Toast.makeText(this, "네비게이션 앱을 설치하지 않았습니다.", Toast.LENGTH_SHORT).show()
}
.create()
alertDialogBuilder.show()
startActivity(intent)
}
주소를 검색하고 내비게이션으로 넘어갈때 주소가 내비 로 바로 가져가지게 하고 싶은데
아무리 노력해주 주소가 안넘어가지네요. ㅠ.ㅠ 흠
고수님들 도와 주시면 감사하겠습니다..