要求用户在没有 GoogleAPI 或 Google Play 服务的情况下在 android 中启用 GPS 定位 [英] Ask user to enable GPS location in android without GoogleAPI or Google Play Services
问题描述
当设备的 GPS 位置被禁用时,我想向用户显示一条消息,他可以在其中按确定"启用它或按取消"保持原样.我找到了很多示例,但所有示例都使用 GoogleAPI 或 Google Play 服务.还有其他方法吗?
When the GPS location of a device is disabled, I want to show a message to the user, where he can press "OK" to enable it or "Cancel" to leave it as it is. I found a lot of examples but all of them either use the GoogleAPI or Google Play Services. Is there another way?
推荐答案
如对类似问题的回答所述,这不太可能.我使用 locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
来检查是否启用了 GPS 定位服务.
As stated in answers to similar questions, this is not quite possible.
I use locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
to check whether the GPS location service is enabled.
如果没有,我会提示用户启用它并将他们定向到android的gps位置设置.他们可以回击以返回应用:
If not, I prompt the user to enable it and direct them to the gps location settings of android. They can hit back to return to the app:
new AlertDialog.Builder(MainActivity.this)
.setMessage("GPS Location is disabled")
.setPositiveButton("ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface paramDialogInterface, int paramInt) {
MainActivity.this.startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
}
})
.setNegativeButton("Cancel", null)
.show();
Toast.makeText(MainActivity.this, "Canceled",Toast.LENGTH_LONG).show();
这篇关于要求用户在没有 GoogleAPI 或 Google Play 服务的情况下在 android 中启用 GPS 定位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!