Ayarlar sayfasına gitmeden konum hizmetlerini açın


122

Kullanıcıdan ayarlar sayfasına gitmesini ve konum hizmetlerini etkinleştirip tekrar geri gelmesini istemenin geleneksel yaklaşımına karşın, en son uygulamaların bazılarında aynı şeyi yapmanın daha basit bir yolunu fark ettim.

Aşağıdaki ekran görüntüsüne bakıldığında, kullanıcıya tek bir tıklama ile konum hizmetlerini etkinleştirmesi için bir iletişim kutusu gönderir ve bu uygulamalarda çalışır.

Aynı şeyi nasıl başarabilirim?

görüntü açıklamasını buraya girin


14
Olumsuz seçmen (ler) nedeni söyleyebilir mi?
GAMA

4
Bu soruyu sorduğunuz için teşekkür ederiz. Yukarı olarak
Lokesh Pandey

1
@GAMA Stackoverflow böyle çalışır! İnsanların olumsuz oy kullanmak için bir nedene ihtiyacı yok. Böylesine düşmanca ve aynı zamanda büyük bir topluluk!

Yanıtlar:


150

Bu iletişim kutusu, Google Play Hizmetlerinde bulunan LocationSettingsRequest.Builder tarafından oluşturulur .

Uygulamanıza bir bağımlılık eklemeniz gerekiyor build.gradle:

compile 'com.google.android.gms:play-services-location:10.0.1'

O zaman bu minimal örneği kullanabilirsiniz:

private void displayLocationSettingsRequest(Context context) {
    GoogleApiClient googleApiClient = new GoogleApiClient.Builder(context)
            .addApi(LocationServices.API).build();
    googleApiClient.connect();

    LocationRequest locationRequest = LocationRequest.create();
    locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    locationRequest.setInterval(10000);
    locationRequest.setFastestInterval(10000 / 2);

    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest);
    builder.setAlwaysShow(true);

    PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build());
    result.setResultCallback(new ResultCallback<LocationSettingsResult>() {
        @Override
        public void onResult(LocationSettingsResult result) {
            final Status status = result.getStatus();
            switch (status.getStatusCode()) {
                case LocationSettingsStatusCodes.SUCCESS:
                    Log.i(TAG, "All location settings are satisfied.");
                    break;
                case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                    Log.i(TAG, "Location settings are not satisfied. Show the user a dialog to upgrade location settings ");

                    try {
                        // Show the dialog by calling startResolutionForResult(), and check the result
                        // in onActivityResult().
                        status.startResolutionForResult(MainActivity.this, REQUEST_CHECK_SETTINGS);
                    } catch (IntentSender.SendIntentException e) {
                        Log.i(TAG, "PendingIntent unable to execute request.");
                    }
                    break;
                case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                    Log.i(TAG, "Location settings are inadequate, and cannot be fixed here. Dialog not created.");
                    break;
            }
        }
    });
}

Tam örneği burada bulabilirsiniz .


1
Üzgünüm ama ilk iki satırı anlamadım:You need to add a dependency to your app build.gradle: compile 'com.google.android.gms:play-services:8.1.0'
GAMA

Google Play Hizmetinin nasıl ayarlanacağıyla ilgili daha fazla bilgiyi burada bulabilirsiniz
Mattia Maestrini

build.gradle nerede bulunur?
GAMA

Uygulama modülü dizininizin içinde. Genellikle dizinin adıapp
Mattia Maestrini

3
SettingsApi artık sınırlandırılmıştır.
Sagar Kacha

27

Aşağıda belirtilen adımları izleyin

1) Bir oluşturun LocationRequestdileğin göre

LocationRequest mLocationRequest = LocationRequest.create()
           .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
           .setInterval(10 * 1000)
           .setFastestInterval(1 * 1000);

2) BirLocationSettingsRequest.Builder

LocationSettingsRequest.Builder settingsBuilder = new LocationSettingsRequest.Builder()
               .addLocationRequest(mLocationRequest);
settingsBuilder.setAlwaysShow(true);

3) alın LocationSettingsResponse TaskAşağıdaki kodu kullanarak

Task<LocationSettingsResponse> result = LocationServices.getSettingsClient(this)
              .checkLocationSettings(settingsBuilder.build());

Not: LocationServices.SettingsApi kullanımdan kaldırılmıştır, bu nedenle SettingsClientYerine kullanın .

4) Bir ekleme OnCompleteListenerTask.When gelen sonucu elde etmek için Tasktamamlamalar, istemci gelen durum koduna bakarak konum ayarlarını kontrol edebilirsiniz LocationSettingsResponsenesne.

result.addOnCompleteListener(new OnCompleteListener<LocationSettingsResponse>() {
    @Override
    public void onComplete(@NonNull Task<LocationSettingsResponse> task) {
    try {
        LocationSettingsResponse response = 
                          task.getResult(ApiException.class);
        } catch (ApiException ex) {
            switch (ex.getStatusCode()) {
                case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                    try {
                        ResolvableApiException resolvableApiException = 
                                 (ResolvableApiException) ex;
                            resolvableApiException
                                   .startResolutionForResult(MapsActivity.this, 
                                         LOCATION_SETTINGS_REQUEST);
                    } catch (IntentSender.SendIntentException e) {

                    }
                    break;
                case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:

                    break;
            }
        }
    }
});  

DURUM 1: LocationSettingsStatusCodes.RESOLUTION_REQUIRED Konum etkin değil, ancak kullanıcıdan iletişim kutusuyla konumu açmasını isteyerek (arayarak startResolutionForResult) konumu etkinleştirmesini isteyebiliriz .

Google Harita Konum Ayarları İsteği

DURUM 2: LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE Konum ayarları tatmin edici değil. Ancak, ayarları düzeltmenin bir yolu yok, bu nedenle iletişim kutusunu göstermeyeceğiz.

5) OnActivityResult kullanıcı eylemini konum ayarları iletişim kutusunda alabiliriz. RESULT_OK=> Kullanıcı Konumu açtı. RESULT_CANCELLED- Kullanıcı konum ayarlama isteğini reddetti.


11

Google haritalarına Benzer Çalışıyor

Build.gradle dosyasına Bağımlılık ekleyin

compile 'com.google.android.gms:play-services:8.3.0'

şu ya da bu

compile 'com.google.android.gms:play-services-location:10.0.1'

görüntü açıklamasını buraya girin

import android.content.Context;
import android.content.IntentSender;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.PendingResult;
import com.google.android.gms.common.api.ResultCallback;
import com.google.android.gms.common.api.Status;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.location.LocationSettingsRequest;
import com.google.android.gms.location.LocationSettingsResult;
import com.google.android.gms.location.LocationSettingsStatusCodes;

import java.util.List;

public class LocationOnOff_Similar_To_Google_Maps extends AppCompatActivity {

    protected static final String TAG = "LocationOnOff";

    private GoogleApiClient googleApiClient;
    final static int REQUEST_LOCATION = 199;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        this.setFinishOnTouchOutside(true);

        // Todo Location Already on  ... start
        final LocationManager manager = (LocationManager) LocationOnOff_Similar_To_Google_Maps.this.getSystemService(Context.LOCATION_SERVICE);
        if (manager.isProviderEnabled(LocationManager.GPS_PROVIDER) && hasGPSDevice(LocationOnOff_Similar_To_Google_Maps.this)) {
            Toast.makeText(LocationOnOff_Similar_To_Google_Maps.this,"Gps already enabled",Toast.LENGTH_SHORT).show();
            finish();
        }
        // Todo Location Already on  ... end

        if(!hasGPSDevice(LocationOnOff_Similar_To_Google_Maps.this)){
            Toast.makeText(LocationOnOff_Similar_To_Google_Maps.this,"Gps not Supported",Toast.LENGTH_SHORT).show();
        }

        if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER) && hasGPSDevice(LocationOnOff_Similar_To_Google_Maps.this)) {
            Log.e("keshav","Gps already enabled");
            Toast.makeText(LocationOnOff_Similar_To_Google_Maps.this,"Gps not enabled",Toast.LENGTH_SHORT).show();
            enableLoc();
        }else{
            Log.e("keshav","Gps already enabled");
            Toast.makeText(LocationOnOff_Similar_To_Google_Maps.this,"Gps already enabled",Toast.LENGTH_SHORT).show();
        }
    }


    private boolean hasGPSDevice(Context context) {
        final LocationManager mgr = (LocationManager) context
                .getSystemService(Context.LOCATION_SERVICE);
        if (mgr == null)
            return false;
        final List<String> providers = mgr.getAllProviders();
        if (providers == null)
            return false;
        return providers.contains(LocationManager.GPS_PROVIDER);
    }

    private void enableLoc() {

        if (googleApiClient == null) {
            googleApiClient = new GoogleApiClient.Builder(LocationOnOff_Similar_To_Google_Maps.this)
                    .addApi(LocationServices.API)
                    .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
                        @Override
                        public void onConnected(Bundle bundle) {

                        }

                        @Override
                        public void onConnectionSuspended(int i) {
                            googleApiClient.connect();
                        }
                    })
                    .addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() {
                        @Override
                        public void onConnectionFailed(ConnectionResult connectionResult) {

                            Log.d("Location error","Location error " + connectionResult.getErrorCode());
                        }
                    }).build();
            googleApiClient.connect();

            LocationRequest locationRequest = LocationRequest.create();
            locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
            locationRequest.setInterval(30 * 1000);
            locationRequest.setFastestInterval(5 * 1000);
            LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
                    .addLocationRequest(locationRequest);

            builder.setAlwaysShow(true);

            PendingResult<LocationSettingsResult> result =
                    LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build());
            result.setResultCallback(new ResultCallback<LocationSettingsResult>() {
                @Override
                public void onResult(LocationSettingsResult result) {
                    final Status status = result.getStatus();
                    switch (status.getStatusCode()) {
                        case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                            try {
                                // Show the dialog by calling startResolutionForResult(),
                                // and check the result in onActivityResult().
                                status.startResolutionForResult(LocationOnOff_Similar_To_Google_Maps.this, REQUEST_LOCATION);

                                finish();
                            } catch (IntentSender.SendIntentException e) {
                                // Ignore the error.
                            }
                            break;
                    }
                }
            });
        }
    }

}

2
AyarlarApi artık kullanımdan kaldırıldı
Sagar Kacha

2
SettingsApi artık kullanımdan kaldırılmıştır. Şimdi SettingsClient'ı kullanın: developers.google.com/android/reference/com/google/android/gms/…
Rishabh Chandel

9
implementation 'com.google.android.gms:play-services-location:16.0.0'

Değişken Beyanı

private SettingsClient mSettingsClient;
private LocationSettingsRequest mLocationSettingsRequest;
private static final int REQUEST_CHECK_SETTINGS = 214;
private static final int REQUEST_ENABLE_GPS = 516;

Aşağıdaki Kodu Kullanarak İletişim Kutusunu Açın

LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
builder.addLocationRequest(new LocationRequest().setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY));
builder.setAlwaysShow(true);
mLocationSettingsRequest = builder.build();

mSettingsClient = LocationServices.getSettingsClient(YourActivity.this);

mSettingsClient
    .checkLocationSettings(mLocationSettingsRequest)
    .addOnSuccessListener(new OnSuccessListener<LocationSettingsResponse>() {
        @Override
        public void onSuccess(LocationSettingsResponse locationSettingsResponse) {
            //Success Perform Task Here
        }
    })
    .addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            int statusCode = ((ApiException) e).getStatusCode();
            switch (statusCode) {
                case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                    try {
                        ResolvableApiException rae = (ResolvableApiException) e;
                        rae.startResolutionForResult(YourActivity.this, REQUEST_CHECK_SETTINGS);
                    } catch (IntentSender.SendIntentException sie) {
                        Log.e("GPS","Unable to execute request.");
                    }
                    break;
                case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                    Log.e("GPS","Location settings are inadequate, and cannot be fixed here. Fix in Settings.");
            }
        }
    })
    .addOnCanceledListener(new OnCanceledListener() {
        @Override
        public void onCanceled() {
            Log.e("GPS","checkLocationSettings -> onCanceled");
        }
    });

onActivityResult

@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == REQUEST_CHECK_SETTINGS) {
        switch (resultCode) {
            case Activity.RESULT_OK:
                //Success Perform Task Here
                break;
            case Activity.RESULT_CANCELED:
                Log.e("GPS","User denied to access location");
                openGpsEnableSetting();
                break;
        }
    } else if (requestCode == REQUEST_ENABLE_GPS) {
        LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        boolean isGpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);

        if (!isGpsEnabled) {
            openGpsEnableSetting();
        } else {
            navigateToUser();
        }
    }
}

private void openGpsEnableSetting() {
    Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
    startActivityForResult(intent, REQUEST_ENABLE_GPS);
}   

Teşekkürler! Bu kodu parça halinde kullanırsanız, stackoverflow.com/a/39579124/2914140'a bakın : rae.startResolutionForResult(activity, REQUEST_CHECK_SETTINGS)çağrı yerine startIntentSenderForResult(rae.getResolution().getIntentSender(), REQUEST_CHECK_SETTINGS, null, 0, 0, 0, null), aksi takdirde onActivityResult()çağrılmaz.
CoolMind

@CoolMind Teşekkürler fragman için buna ihtiyaç duyan biri için kullanılabilir
Ketan Ramani

@CoolMind, benzer bir şey kullanmak mümkün mü startIntentSenderForResult yöntemdeopenGpsEnableSetting() mü?
Aliton Oliveira

@AlitonOliveira, ayrıntılarıyla anlatır mısınız? Kodda, openGpsEnableSetting()GPS ayarlarını etkinleştirmek için basitçe bir iletişim kutusu açılır. Bittikten sonra onActivityResult()ile çağrılırrequestCode == REQUEST_ENABLE_GPS .
CoolMind

onActivityResult()Aktiviteden çağrılıyor ve sonucu Fragmentbenzerine döndürmenin mümkün olup olmadığını merak ediyordum startIntentSenderForResult.
Aliton Oliveira

8

Mattia Maestrini +1 sayesinde

Xamarin çözümü:

using Android.Gms.Common.Apis;
using Android.Gms.Location;

public const int REQUEST_CHECK_SETTINGS = 0x1;

private void DisplayLocationSettingsRequest()
{
    var googleApiClient = new GoogleApiClient.Builder(this).AddApi(LocationServices.API).Build();
    googleApiClient.Connect();

    var locationRequest = LocationRequest.Create();
    locationRequest.SetPriority(LocationRequest.PriorityHighAccuracy);
    locationRequest.SetInterval(10000);
    locationRequest.SetFastestInterval(10000 / 2);

    var builder = new LocationSettingsRequest.Builder().AddLocationRequest(locationRequest);
    builder.SetAlwaysShow(true);

    var result = LocationServices.SettingsApi.CheckLocationSettings(googleApiClient, builder.Build());
    result.SetResultCallback((LocationSettingsResult callback) =>
    {
        switch (callback.Status.StatusCode)
        {
            case LocationSettingsStatusCodes.Success:
                {
                    DoStuffWithLocation();
                    break;
                }
            case LocationSettingsStatusCodes.ResolutionRequired:
                {
                    try
                    {
                        // Show the dialog by calling startResolutionForResult(), and check the result
                        // in onActivityResult().
                        callback.Status.StartResolutionForResult(this, REQUEST_CHECK_SETTINGS);
                    }
                    catch (IntentSender.SendIntentException e)
                    {
                    }

                    break;
                }
            default:
                {
                    // If all else fails, take the user to the android location settings
                    StartActivity(new Intent(Android.Provider.Settings.ActionLocationSourceSettings));
                    break;
                }
        }
    });
}

protected override void OnActivityResult(int requestCode, Android.App.Result resultCode, Intent data)
{
    switch (requestCode)
    {
        case REQUEST_CHECK_SETTINGS:
            {
                switch (resultCode)
                {
                    case Android.App.Result.Ok:
                        {
                            DoStuffWithLocation();
                            break;
                        }
                    case Android.App.Result.Canceled:
                        {
                            //No location
                            break;
                        }
                }
                break;
            }
    }
}

NOT:

Bu, Huawei'de veya Google hizmetleri yüklü olmayan diğer cihazlarda çalışmayacaktır.


Çalışmıyor!! Kodun tamamını paylaşır mısınız
Omkar

Android Activity'in OnCreate yönteminden DisplayLocationSettingsRequest () yöntemini çağırmaya çalışıyorum. Ancak maalesef Konum ayarını açan konum belirleme isteği açılır penceresini görüntüleyemiyorum. Lütfen bana yardım eder misin?
Omkar

@Omkar, Nuget aracılığıyla Xamarin.GooglePlayServices.Location'ı kurdunuz mu? Yukarıdaki iki satırı eklediniz miusing android.Gms.Common.Apis; using Android.Gms.Location; ? Çağırdıktan sonra LocationServices.SettingsApi.CheckLocationSettingssizi içinde geri arama alabilirim result.SetResultCallback(? Bunların her birine bir kırılma noktası
Pierre

Evet tüm ön koşulları ekledim. Ve Id = 1, Status = WaitingForActivation, Method = (null) olarak sonuç aldım. Ancak bu bekleme süresi, uzun süre beklendiği gibi sonsuzdur ve sonuç alınamamıştır.
Omkar

4

Android Marshmallow 6, çalışma zamanı iznini destekler. Çalışma zamanı izinleri yalnızca Marshmallow'da çalışır ve Marshmallow öncesi sürümde hala eski şekilde çalışır.

Bu Android Geliştirici resmi Videosunda bunun hakkında daha fazla bilgi edinebilirsiniz:

https://www.youtube.com/watch?v=C8lUdPVSzDk

Ve izin istiyoruz: http://developer.android.com/training/permissions/requesting.html


Marshmallow API'leri geliştirme amaçlı kullanılabilir mi?
GAMA

Bu, ekran görüntüsü aracılığıyla gösterilen iş akışının yalnızca Marshmallow ve daha sonra gerçekleştirilebileceği anlamına mı geliyor?
GAMA

Evet, belgelerde belirtildiği gibi API seviyesi 23, bu nedenle yalnızca Marshmallow ve daha yeni sürümlerde çalışacaktır.
Sharj

Kendi özel iletişim aynı davranışı elde etmek için herhangi bir yolu
Srishti Roy

4

Cevap için teşekkürler Mattia Maestrini, bunu kullanarak eklemek istiyorum.

compile 'com.google.android.gms:play-services-location:8.1.0'

yeterli olur. Bu, uygulamanızın gereksiz kitaplıklar içermesini önler ve yöntem sayınızı düşük tutmanıza yardımcı olur.


2

Kotlin Çözümü

Ekle build.gradle(Module:app)

implementation 'com.google.android.gms:play-services-location:17.0.0'
implementation 'com.google.android.gms:play-services-maps:17.0.0'

bundan sonra bu işlevi yarat

fun enablegps() {

    val mLocationRequest = LocationRequest.create()
        .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
        .setInterval(2000)
        .setFastestInterval(1000)

    val settingsBuilder = LocationSettingsRequest.Builder()
        .addLocationRequest(mLocationRequest)
    settingsBuilder.setAlwaysShow(true)

    val result = LocationServices.getSettingsClient(this).checkLocationSettings(settingsBuilder.build())
    result.addOnCompleteListener { task ->

        //getting the status code from exception
        try {
            task.getResult(ApiException::class.java)
        } catch (ex: ApiException) {

            when (ex.statusCode) {

                LocationSettingsStatusCodes.RESOLUTION_REQUIRED -> try {

                    Toast.makeText(this,"GPS IS OFF",Toast.LENGTH_SHORT).show()

                    // Show the dialog by calling startResolutionForResult(), and check the result
                    // in onActivityResult().
                    val resolvableApiException = ex as ResolvableApiException
                    resolvableApiException.startResolutionForResult(this,REQUEST_CHECK_SETTINGS
                    )
                } catch (e: IntentSender.SendIntentException) {
                    Toast.makeText(this,"PendingIntent unable to execute request.",Toast.LENGTH_SHORT).show()

                }

                LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE -> {

                    Toast.makeText(
                        this,
                        "Something is wrong in your GPS",
                        Toast.LENGTH_SHORT
                    ).show()

                }


            }
        }



    }


}

1

Son Marshmallow güncellemesiyle, Konum ayarı açık olsa bile, uygulamanızın açıkça izin istemesi gerekecektir. Bunu yapmanın önerilen yolu, uygulamanızın, kullanıcının izni gerektiği gibi değiştirebileceği İzinler bölümünü göstermektir. Bunu yapmak için kod parçacığı aşağıdaki gibidir:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {if (this.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {final AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Location Permission");
        builder.setMessage("The app needs location permissions. Please grant this permission to continue using the features of the app.");
        builder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, PERMISSION_REQUEST_COARSE_LOCATION);}
        });
        builder.setNegativeButton(android.R.string.no, null);
        builder.show();
    }
} else {
    // do programatically as show in the other answer 
}

Ve onRequestPermissionsResultyöntemi aşağıdaki gibi geçersiz kılın :

@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
        switch (requestCode) {
            case PERMISSION_REQUEST_COARSE_LOCATION: {
                if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    Log.d(TAG, "coarse location permission granted");
                } else {
                    Intent intent = new Intent();
                    intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                    Uri uri = Uri.fromParts("package", getPackageName(), null);
                    intent.setData(uri);
                    startActivity(intent);
                }
            }
        }
    }

Başka bir yaklaşım da, hangi konum sağlayıcılarının etkinleştirildiğini sorgulamak için SettingsApi'yi kullanabilirsiniz . Hiçbiri etkinleştirilmezse, ayarı uygulama içinden değiştirmek için bir iletişim kutusu açabilirsiniz.


1

Araştırmam sırasında bulduğum en basit yol, bu konum talep etme işlemi için bir Util sınıfı oluşturmak ve ardından gps'i bizim için AÇMAK için çağırmak.

Lütfen bu blogu kontrol edin! Bütün hikayeyi anlattı.

Sitemizi kullandığınızda şunları okuyup anladığınızı kabul etmiş olursunuz: Çerez Politikası ve Gizlilik Politikası.
Licensed under cc by-sa 3.0 with attribution required.