[英]My android service working fine on other devices, but on some devices
[英]Location Service not working fine in some Android devices
如果设备的GPS位置已禁用,我将使用以下代码向用户显示一个对话框。
final AlertDialog.Builder builder =
new AlertDialog.Builder(activity);
final String action = Settings.ACTION_LOCATION_SOURCE_SETTINGS;
final String message = "Enable GPS"
+ " service to find current location. And change the location mode to high accuracy for the app to perform accurately. Click OK to go to"
+ " location services settings to let you do so.";
builder.setMessage(message)
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface d, int id) {
activity.startActivity(new Intent(action));
d.dismiss();
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface d, int id) {
d.cancel();
}
});
builder.create().show();
到目前为止,我已经在两个设备MotoG(v 4.4.4)和Samsung duos(v 4.1.2)上测试了此代码。
我在两个设备上都打开了GPS。 在MotoG中,我可以得到正确的结果,但返回的结果是true,但在三星设备中,返回的结果是false。
但是三星设备却向我返回了地址(我正在连接到定位服务以获取当前地址)。 我在位置客户端的onConnected方法中获取地址。 如果返回地址,那么应该启用GPS吗?
为什么有人知道这个问题?
尝试这个
public void showSettingsAlert(){
AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);
// Setting Dialog Title
alertDialog.setTitle("GPS settings");
// Setting Dialog Message
alertDialog.setMessage("GPS is not enabled. Do you want to go to settings menu?");
// Setting Icon to Dialog
//alertDialog.setIcon(R.drawable.delete);
// 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);
mContext.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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.