An warware: yadda ake bincika idan an kunna wurin aiki android

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.

Shafi posts:

Leave a Comment