限制用户在android中禁用gps选项
我的应用程序将经常基于GPS监控用户位置。现在的难题是用户可以手动禁用设备中的GPS选项…如何限制用户禁用GPS选项。?您可以检查GPS是否已禁用限制用户在android中禁用gps选项,android,gps,Android,Gps,我的应用程序将经常基于GPS监控用户位置。现在的难题是用户可以手动禁用设备中的GPS选项…如何限制用户禁用GPS选项。?您可以检查GPS是否已禁用 LocationManager locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); boolean isGPSEnabled = locManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
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
}
我希望这些有帮助,快乐编码!:) 谢谢…在应用程序运行时是否可以限制禁用gps选项???不,我认为不可能。到目前为止,我无法找到一种方法来控制android系统的设置应用程序。