2016-03-29 8 views
0

Kullanıcıların GPS ayarlarını devre dışı bırakıp bırakmadığını kontrol etmek için herhangi bir çözüm var mı? Uygulamamı açıp, android sistemin en iyi araç çubuğunu aç, GPS'i devre dışı bırak ve bu araç çubuğunu kapat. Şu anda GPS'in durumunun değişip değişmediğini kontrol etmek istiyorum. GPS'in onResume() öğesinde etkin olup olmadığını kontrol ediyorum, ancak bu çözüm, yalnızca onResume() işlevi devre dışı bırakıldığında kullanıcı GPS'yi etkinleştirdiğinde çalışır. Herhangi bir fikrin var mı?Kullanıcının GPS ayarlarını devre dışı bırakıp kilitlemediğini kontrol et

Düzenleme: Bu olabilir sınıftır:

public class PrivacyActivity extends BaseActivity implements GpsStatus.Listener, LocationListener{ 


    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_privacy); 

    } 

    @Override 
    protected void onPause() { 
     super.onPause(); 
    } 

    @Override 
    protected void onResume() { 
     super.onResume(); 
    } 

    @Override 
    public void onGpsStatusChanged(int event) { 
     switch (event) { 
     case GpsStatus.GPS_EVENT_SATELLITE_STATUS: 
      Toast.makeText(this, "ads", Toast.LENGTH_LONG).show(); 

      break; 
     case GpsStatus.GPS_EVENT_FIRST_FIX: 
      Toast.makeText(this, "ads1", Toast.LENGTH_LONG).show(); 

      break; 
     } 
    } 

    @Override 
    public void onLocationChanged(Location location) { 

    } 

    @Override 
    public void onStatusChanged(String provider, int status, Bundle extras) { 
     Toast.makeText(getApplicationContext(), "ads2", Toast.LENGTH_LONG).show(); 
    } 

    @Override 
    public void onProviderEnabled(String provider) { 
     Toast.makeText(getApplicationContext(), "ads2", Toast.LENGTH_LONG).show(); 
    } 

    @Override 
    public void onProviderDisabled(String provider) { 
     Toast.makeText(getApplicationContext(), "ads2", Toast.LENGTH_LONG).show(); 
    } 
} 

ve gps devre dışı zaman tost görmedim.

+0

Olası kopyası [GPS alıcısının mevcut durumunu nasıl kontrol edebilirim?] (Http://stackoverflow.com/questions/2021176/how-can-i-check-the-current-status-of-the -GPS-alıcı) –

cevap

0

Referans locationListener daha fazla bilgi 'alabilirsiniz LocationListener sınıf

// Acquire a reference to the system Location Manager 
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); 

// Define a listener that responds to location updates 
LocationListener locationListener = new LocationListener() { 
    public void onLocationChanged(Location location) { 
     // Called when a new location is found by the network location provider. 
     makeUseOfNewLocation(location); 
    } 

    public void onStatusChanged(String provider, int status, Bundle extras) {} 

    public void onProviderEnabled(String provider) { 
     Log.i("Example", "GPS is ON"); 
    } 

    public void onProviderDisabled(String provider) { 
     Log.i("Example", "GPS is OFF"); 
    } 
    }; 

// Register the listener with the Location Manager to receive location updates 
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); 

kullanabilirsiniz. Kullanıcı GPS ayarlarından devre dışı bırakılmışsa ,ProviderDisabled yöntemi tetiklenecektir.. Yöntemin içindeki amaç, kullanıcıyı doğrudan konum ayarlarına götürecektir.

Test edilmiş ve düzgün çalışıyor.

İlgili konular