Rubuta labarin mai faษi game da yadda ake bincika idan an kunna wuri akan na'urar Android na iya buฦatar cikakkiyar fahimtar shirye-shiryen Java da kuma amfani da ษakunan karatu na Android daban-daban. Don haka, bari mu shiga cikin wannan.
A cikin shimfidar wuri na aikace-aikacen wayar hannu na zamani, samun damar wurin mai amfani ya zama mahimmanci don samar da keษaษษen gogewa dangane da matsayin yanki na mai amfani. Wannan aikin yana da yawa a cikin na'urori masu ฦarfi da Android. Koyaya, tantance ko an kunna wurin ko a'a lamari ne mai mahimmanci shima.
public boolean isLocationEnabled(Context context) { int locationMode = 0; String locationProviders; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { try { locationMode = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE); } catch (Settings.SettingNotFoundException e) { e.printStackTrace(); } return locationMode != Settings.Secure.LOCATION_MODE_OFF; } else { locationProviders = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED); return !TextUtils.isEmpty(locationProviders); } }
Fahimtar lambar
Lambar da aka bayar a sama tana bincika idan an kunna sabis ษin wurin akan kowace na'urar Android ta manyan matakai biyu:
- Idan nau'in na'urar KitKat ne ko sama, yana ฦoฦarin samun saitin yanayin wuri kuma yana tabbatar da ko ban da 'Yanayin Wuri'. Idan haka ne, yana tabbatar da cewa an kunna wurin.
- Don na'urorin da ke gudana akan nau'ikan da suka girmi KitKat, yana samun jerin masu ba da izini da kuma bincika idan babu komai a ciki. Idan lissafin bai fanko ba, an tabbatar da cewa an kunna wurin.
Matsayin Dakunan karatu da Ayyuka daban-daban
A cikin wannan lambar, mun yi amfani da wasu takamaiman ayyuka da ษakunan karatu, da farko daga Kit ษin Haษaka Android:
- Gina.VERSION.SDK_INT: Wannan fili ne wanda ke riฦe da nau'in SDK na dandamali a halin yanzu yana aiki akan na'urar.
- Saituna.Amintacce: Wannan aji ne wanda ke kula da samun dama ga amintattun saitunan tsarin duniya, da farko saitin tsarin da ke shafar sirrin mai amfani.
- Saituna.Secure.getInt: Wannan hanyar tana dawo da amintaccen ฦimar saitin lamba don sunan da aka bayar.
- Saituna.Amintacce.LOCATION_MODE: Ana amfani da wannan don samun saitin yanayin wuri na yanzu.
- Saituna.Amintacce.LOCATION_PROVIDERS_ALLOWED: Yana samun jerin masu ba da wurin da aka yarda.
Daidaita don nau'ikan Android daban-daban
Android ta samu ci gaba sosai cikin shekaru goma, kuma kowace sigar ta zo da takamaiman fasali da saitunan sa. Don haka, lambar koyarwa dole ne ta haifar da ษangarorin dabarar da ke bayyana a cikin nau'ikan Android daban-daban.
Lambar da aka ba ta cikakke tana bincika wurin da aka kunna a duk nau'ikan Android, tare da takamaiman mai da hankali kan sigar KitKat, inda aka gabatar da 'Yanayin Wuri'. Wannan dichotomy ya raba tsarin kimantawa zuwa manyan nau'i biyu - ษaya don nau'ikan Android KitKat da sama, da kuma wani dabam na nau'ikan da ke ฦasa KitKat.
Don taฦaitawa, bincika ko an kunna sabis ษin wurin akan na'urar Android babban haske ne mai kima ga masu haษakawa. Yana taimakawa wajen fahimtar ayyuka kuma yana bawa masu haษaka damar bayyana ฦarin fassarar takamaiman aikace-aikacen mai amfani.