我的应用程序将经常监测用户的位置基于GPS..now的谜语是用户可以手动禁用他们的device...how中的全球定位系统选项,以限制用户禁用全球定位系统选项。
发布于 2013-02-21 21:49:19
您可以检查GPS是否被禁用。
LocationManager locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
boolean isGPSEnabled = locManager.isProviderEnabled(LocationManager.GPS_PROVIDER);然后,如果isGPSEnabled为false,则打开一个对话框,以便打开gps设置
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
}我希望这些对你有所帮助,祝你编码愉快!:)
https://stackoverflow.com/questions/15003756
复制相似问题