λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
🍏 Client/Android

[Android/Kotlin] BLE Device μŠ€μΊ”μ‹œ μœ„μΉ˜ κΆŒν•œν—ˆμš© (Fine vs Coarse)

by Danna 2020. 11. 4.
728x90
728x90

μ΅œκ·Όμ— μ•ˆλ“œλ‘œμ΄λ“œ κ°œλ°œμ„ μ‹œμž‘ν•΄μ„œ BLE 톡신과 차트 라이브러리λ₯Ό μ‚¬μš©ν•œ μ–΄ν”Œλ¦¬μΌ€μ΄μ…˜μ„ λ§Œλ“€κ³  μžˆλ‹€.

 

BLE Device λ₯Ό μŠ€μΊ”ν•˜κΈ° μœ„ν•΄μ„œλŠ” μœ„μΉ˜ κΆŒν•œμ„ ν—ˆμš©ν•΄μ•Ό ν•˜λŠ”λ°, μœ„μΉ˜ κΆŒν•œμ˜ μ’…λ₯˜μ— λŒ€ν•΄ ν—·κ°ˆλ Έμ—ˆλ‹€.

 

일단, Activity κ°€ μ•„λ‹Œ AppCompatActivity λ₯Ό μƒμ†λ°›μ•˜μ„ λ•Œ κΆŒν•œ ν—ˆμš©μ„ 물어보기 μœ„ν•΄μ„œλŠ” μ•„λž˜ ν•¨μˆ˜λ₯Ό μ΄μš©ν•˜λ©΄ λœλ‹€.

 

ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), 1)

 

arrayOf() ν•¨μˆ˜ μ•ˆμ— μ›ν•˜λŠ” μœ„μΉ˜ κΆŒν•œμ„ μΆ”κ°€ν•˜λ©΄ λœλ‹€.

 

LOCATION κ³Ό κ΄€λ ¨λœ permission μ’…λ₯˜λŠ” λ‹€μŒκ³Ό κ°™λ‹€.

  • ACCESS_FINE_LOCATION : GPS, λ„€νŠΈμ›Œν¬λ₯Ό μ‚¬μš©ν•΄ μœ„μΉ˜ 정보 확인
  • ACCESS_COARSE_LOCATION : λ„€νŠΈμ›Œν¬λ§Œ μ‚¬μš©ν•΄ μœ„μΉ˜ 정보 확인
  • ACCESS_BACKGROUND_LOCATION : μœ„μΉ˜ κΆŒν•œ ν—ˆμš©μ„ λ¬Όμ–΄λ³Ό λ•Œ, 항상 ν—ˆμš© μ˜΅μ…˜μ΄ μΆ”κ°€λœλ‹€. ν•΄λ‹Ή permission 을 μΆ”κ°€ν•˜μ§€ μ•Šμ•˜μ„ λ•Œμ—λŠ” "μ•± μ‚¬μš© μ€‘μ—λ§Œ ν—ˆμš©" 만 λ‚˜νƒ€λ‚¬λ‹€. 

λ‹€λ§Œ, BLE λ””λ°”μ΄μŠ€ μŠ€μΊ”μ‹œμ—λŠ” ACCESS_COARSE_LOCATION μœΌλ‘œ κΆŒν•œμ„ 얻은 κ²½μš°μ—λŠ” λ˜μ§€ μ•Šμ•˜κ³ , ACCESS_FINE_LOCATION μœΌλ‘œ κΆŒν•œμ„ μ–»μ–΄μ•Όλ§Œ κ°€λŠ₯ν–ˆλ‹€.

ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION 만 μΆ”κ°€ν•œ 경우
ACCESS_BACKGROUND_LOCATION λ₯Ό μΆ”κ°€ν•œ 경우


(μ—¬λ‹΄)

κΈ°μ‘΄ μ½”λ“œμ—μ„œλŠ” ACCESS_COARSE_LOCATION κΆŒν•œμœΌλ‘œ λ˜μ–΄μžˆμ—ˆλ‹€.

μ–΄ν”Œ 섀정에 λ“€μ–΄κ°€μ„œ "항상 ν—ˆμš©" μ˜΅μ…˜μ„ 눌러주면 λ””λ°”μ΄μŠ€ μŠ€μΊ”μ΄ 되길래, 항상 ν—ˆμš© μ˜΅μ…˜μΈ 쀄 μ•Œμ•˜λ‹€. 

μ•„λž˜μ™€ 같이 μ½”λ“œλ₯Ό λ°”κΏ¨λŠ”λ°λ„ λ””λ°”μ΄μŠ€ μŠ€μΊ”μ΄ λ˜μ§€ μ•Šμ•˜μ—ˆλ‹€ ..

ActivityCompat.requestPermissions(this, 
	arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION, 
    		Manifest.permission.ACCESS_BACKGROUND_LOCATION), 1)

μ°Έκ³ 

  1. blog.naver.com/PostView.nhn?blogId=sangmanla&logNo=220997369185
728x90
728x90

'🍏 Client > Android' μΉ΄ν…Œκ³ λ¦¬μ˜ λ‹€λ₯Έ κΈ€

[Android] Jetpack - Data binding  (0) 2020.11.25
[Android] MVVM λ””μžμΈνŒ¨ν„΄, Jetpack 아킀텍쳐  (0) 2020.11.25