gpt4 book ai didi

java - 检查网络位置提供程序是否启用的任何替代方法?

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

当我检查

boolean networkReady=manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

我在某些三星手机上是真的,尽管设置中不允许无线定位。

有没有其他方法可以检查此设置并在所有手机上获得正确的值?

最佳答案

下面附上了我在我的应用程序中使用的一些不错的网络实用程序功能,所有这些功能都非常棒!对于位置轮询,肯定是 -> https://github.com/commonsguy/cwac-locpoll

希望这有助于...

public static boolean checkInternetConnection(Context context) {

ConnectivityManager conMgr = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);

// ARE WE CONNECTED TO THE NET?
if (conMgr.getActiveNetworkInfo() != null
&& conMgr.getActiveNetworkInfo().isAvailable()
&& conMgr.getActiveNetworkInfo().isConnected()) {
return true;
} else {
Log.w(TAG, "Internet Connection NOT Present");
return false;
}
}
public static boolean isConnAvailAndNotRoaming(Context context) {

ConnectivityManager conMgr = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);

if (conMgr.getActiveNetworkInfo() != null
&& conMgr.getActiveNetworkInfo().isAvailable()
&& conMgr.getActiveNetworkInfo().isConnected()) {

if(!conMgr.getActiveNetworkInfo().isRoaming())
return true;
else
return false;
} else {
Log.w(TAG, "Internet Connection NOT Present");
return false;
}
}
public static boolean isRoaming(Context context) {

ConnectivityManager conMgr = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);

return (conMgr.getActiveNetworkInfo()!=null && conMgr.getActiveNetworkInfo().isRoaming());
}

关于java - 检查网络位置提供程序是否启用的任何替代方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7985094/

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