0
禁用GPS选项我的应用程序将经常监视基于GPS的用户位置..现在的谜语是用户可以手动禁用他们的设备中的GPS选项...如何限制用户禁用GPS选项。?限制用户在android
禁用GPS选项我的应用程序将经常监视基于GPS的用户位置..现在的谜语是用户可以手动禁用他们的设备中的GPS选项...如何限制用户禁用GPS选项。?限制用户在android
您可以检查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
}
我希望这些帮助,快乐编码! :)
谢谢....是否有可能限制禁用gps选项,而应用程序正在运行???? – immutable 2013-02-21 13:58:55
不,我不认为这是可能的。到目前为止,我无法找到一种方法来控制Android系统的设置应用程序。 – 2013-02-21 14:04:25