gpt4 book ai didi

android - GPS 未启用但 isProviderEnabled() 返回 true

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:58:49 25 4
gpt4 key购买 nike

我可以使用 isProviderEnabled() 检查 GPS 是否打开。如果它没有打开,我将启动 Intent 以便用户可以启用 GPS。最后,我再次检查用户是否启用了 GPS。如果用户不启用 GPS 出来,isProviderEnabled() 仍然返回 NULL。可能是什么问题 ?请指导我。

    String provider = LocationManager.GPS_PROVIDER;
// Check if GPS is enabled
boolean enabled = myLocationManager.isProviderEnabled(provider);

if (!enabled) {
// GPS not enabled
Log.d("", "Provider " + provider + " is not enabled");
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
// Consider the case when user does not enable GPS and come out.
} else {
Log.d("", "Provider is enabled");

}

// Re-check if user has enabled or not. (Note: case: user has not enabled GPS)
enabled = myLocationManager.isProviderEnabled(provider);
if(!enabled)
{

Log.d("","provider not enabled");
}
else
{
// Control is coming here though user has not enabled GPS in settings
Log.d("","GPS is enabled");
}

谢谢,双联实验室

最佳答案

使用此代码检查 GPS 启用并告诉我发生了什么,

private void CheckEnableGPS(){
String provider = Settings.Secure.getString(getContentResolver(),
Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
if(!provider.equals("")){
//GPS Enabled
Toast.makeText(AndroidEnableGPS.this, "GPS Enabled: " + provider,
Toast.LENGTH_LONG).show();
}else{
Intent intent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
startActivity(intent);
}
}

关于android - GPS 未启用但 isProviderEnabled() 返回 true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10117587/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com