2013-02-21 66 views
0

禁用GPS選項我的應用程序將經常監視基於GPS的用戶位置..現在的謎語是用戶可以手動禁用他們的設備中的GPS選項...如何限制用戶禁用GPS選項。?限制用戶在android

回答

2

您可以檢查GPS是否被禁用。

LocationManager locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 

boolean isGPSEnabled = locManager.isProviderEnabled(LocationManager.GPS_PROVIDER); 

然後啓動一個對話框,意圖打開GPS設置,如果isGPSEnabled是假

private void showSettingsGPSAlert() { 

    AlertDialog.Builder alertDialog = new AlertDialog.Builder(this); 

    // Setting Dialog Title 
    alertDialog.setTitle("GPS settings"); 

    // Setting Dialog Message 
    alertDialog.setMessage("GPS is not enabled. Do you want to go to settings menu?"); 

    // On pressing Settings button 
    alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog,int which) { 
      Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); 
      startActivity(intent); 
     } 
    }); 

    // on pressing cancel button 
    alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int which) { 
     dialog.cancel(); 
     } 
    }); 

    // Showing Alert Message 
    alertDialog.show(); 

} 

也能聆聽到你的位置監聽器回調的變化。

public void onProviderDisabled(String provider) { 

     //Do something here. Example tell user that gps is disabled 

} 

public void onProviderEnabled(String provider) { 
    // TODO Auto-generated method stub 

} 

public void onStatusChanged(String provider, int status, Bundle extras) { 
    // TODO Auto-generated method stub 

} 

我希望這些幫助,快樂編碼! :)

+0

謝謝....是否有可能限制禁用gps選項,而應用程序正在運行???? – immutable 2013-02-21 13:58:55

+0

不,我不認爲這是可能的。到目前爲止,我無法找到一種方法來控制Android系統的設置應用程序。 – 2013-02-21 14:04:25