play services location - boostcampwm-2024/and04-Nature-Album GitHub Wiki
๋๋ถ๋ถ์ ๊ฒฝ์ฐ ์ฌ์ฉ์์ ํ์ฌ ์์น์ ๊ด์ฌ์ด ์์ผ๋ฉฐ ์ฌ์ฉ์์ ํ์ฌ ์์น๋ ์ผ๋ฐ์ ์ผ๋ก ๋ง์ง๋ง์ผ๋ก ์๋ ค์ง ๊ธฐ๊ธฐ์ ์์น์ ๊ฐ์ต๋๋ค
Android Developers ๋ง์ง๋ง์ผ๋ก ์๋ ค์ง ์์น ๊ฐ์ ธ์ค๊ธฐ | Sensors and location
ํตํฉ ์์น ์ ๋ณด ์ ๊ณต์๋ Google Play ์๋น์ค์ Location API ์ค ํ๋์ ๋๋ค. ๊ธฐ๋ณธ ์์น ๊ธฐ์ ์ ๊ด๋ฆฌํ๊ณ ๋จ์ํ API๋ฅผ ์ ๊ณตํ๋ฏ๋ก, ๋์ ์์ค์ผ๋ก ์๊ตฌ์ฌํญ(๋์ ์ ํ์ฑ์ด๋ ์ ์ ๋ ฅ ๋ฑ)์ ์ง์ ํ ์ ์์ต๋๋ค. ์ด API๋ ๊ธฐ๊ธฐ์ ๋ฐฐํฐ๋ฆฌ ์ ๋ ฅ ์ฌ์ฉ์ ์ต์ ํํด ์ค๋๋ค.
Google for Developers FusedLocationProviderCliend | Google play services
์ต์ ์ ์์น ์ ํ
private val client by lazy { LocationServices.getSettingsClient(context) }
The main entry point for interacting with the location settings-enabler APIs.
To use this API, first create a LocationSettingsRequest.Builder and add all of the LocationRequests that the app will be using:
private val builder by lazy {
LocationSettingsRequest.Builder().addLocationRequest(
LocationRequest.Builder(
Priority.PRIORITY_BALANCED_POWER_ACCURACY,
Long.MAX_VALUE,
).build()
)
}
LocationRequest.Builder(int priority, long intervalMillis)
- priority : Google for Developers Priority | Google Play services : ์ ํ๋์ ์ ๋ ฅ ์ฌ์ฉ ๊ธฐ์ค
-
*PRIORITY_BALANCED_POWER_ACCURACY
: ์์น ์ ํ๋์ ์ ๋ ฅ ์ฌ์ฉ๊ฐ์ ๊ท ํ ์ ์ง*
-
- intervalMillis : ์์น ์
๋ฐ์ดํธ ์์ฒญ ๊ฐ๊ฒฉ
-
Long.MAX_VALUE
: ์ฐ๋ฆฌ๋ ๋จ์ง GPS ์ํ๊ฒ์ฌ๋ฅผ ์ํด LocationRequest ๊ฐ ํ์ํ๊ธฐ ๋๋ฌธ์ intervalMillis๊ฐ ํ์์๋ค. โ ์ต๋๋ก
-
private fun resolveLocationSettings(
resolvable: ResolvableApiException,
showGPSActivationDialog: (IntentSenderRequest) -> Unit,
) {
val intentSenderRequest = IntentSenderRequest.Builder(resolvable.resolution).build()
try {
showGPSActivationDialog(intentSenderRequest)
} catch (e: IntentSender.SendIntentException) {
e.printStackTrace()
}
}
ResolvableApiException
-
์ฑ์ ์์ฒญ๊ณผ ์์คํ ์ค์ ์ด ์ถฉ๋ํ ๋ ๋ฐ์ํ๋ ์์ธ
-
ResolvableApiException.resolution
: PendingIntent- ์คํจ๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํ PendingIntent (๋์ค์ ์คํ๋ Intent๋ฅผ ์์ฝํด๋๋ ๊ฐ์ฒด)
-
์ด ๊ฐ์ฒด๋ฅผ ํตํด
IntentSenderRequest
๋ฅผ ์ป์ ์ ์๋ค.
- PendingIntent ๊ฐ์ฒด๋ฅผ ์
๋ ฅ์ผ๋ก ๋ฐ์ ํด๋น PendingIntent์ ๋ด์ฅ๋ IntentSender๋ฅผ ์ถ์ถํ์ฌ ์ฌ์ฉ
- IntentSender : Android Developers IntentSender
- ์ด๋ ต๋ค..?
- IntentSender : Android Developers IntentSender
GPT ์์ฝ
- ๋ด๊ฐ ์ค์ ํ ์์ (์: ์๋ฆผ์ ๋ณด๋ด๊ธฐ, ์ค์ ํ๋ฉด ์ด๊ธฐ ๋ฑ)์ ๋ค๋ฅธ ์ฑ์ด ๋์ ์ํํ ์ ์๋๋ก ์์ฒญ์๋ฅผ ๋ง๋ค์ด์ฃผ๋ ์ญํ ์ ๋๋ค.
- IntentSender๋ ๋ฏธ๋ฆฌ ์ค๋นํด๋ Intent๋ฅผ ํน์ ์์ ์ ์ํํ๋๋ก ํ๋ ๋ฐฉ๋ฒ์ ๋๋ค.
์์: ์๋ฆผ์ ํด๋ฆญํ๋ฉด ํน์ ํ๋ฉด์ ์ด๋๋ก ๋ฏธ๋ฆฌ ์ค์ ํด๋๋ ๊ฒ์ด ๊ฐ๋ฅํฉ๋๋ค. ์๋ฆผ์ ํด๋ฆญํ๋ ์์ ์, ๋ฏธ๋ฆฌ ์ค์ ๋ IntentSender๊ฐ ์คํ๋ฉ๋๋ค.
-
๋ค๋ฅธ ์ฑ์ IntentSender๋ฅผ ๋๊ธฐ๋ฉด, ๋ค๋ฅธ ์ฑ์ด ๋ง์น ๋์ธ ๊ฒ์ฒ๋ผ ๋ด ์์ ์ ์ํํ ์ ์๋ ๊ถํ์ ๊ฐ๊ฒ ๋ฉ๋๋ค.
-
๊ทธ๋์ ๋ณดํต IntentSender๋ ๋ด ์ฑ์ ํน์ ์ปดํฌ๋ํธ(์: ๋ด ํ๋ฉด์ด๋ ์๋น์ค)๋ก๋ง ์ฐ๊ฒฐ๋๋๋ก ์ค์ ํ๋ ๊ฒ์ด ์์ ํฉ๋๋ค.
- IntentSender๋ PendingIntent์์ ๋ง๋ค์ด์ง๋๋ค. ์ฆ, PendingIntent.getIntentSender()๋ฅผ ํธ์ถํด IntentSender๋ฅผ ๊ฐ์ ธ์ฌ ์ ์์ต๋๋ค.
- ๋ฐํ ํ์
: IntentSenderRequest
- ์ด ํ์ ์ registerForActivityResult ์ ์ฌ์ฉ๋จ