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

标签 java android location

当我检查

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/

相关文章:

android - "Default activity not found"用于使用 Android Studio 模板创建的可穿戴应用

带有圆角的 Android SlidingTabs 样式选项卡

java - 在 Android 中加密和解密文件的任何优化方式

Android:如何以编程方式在“我的位置”中启用 "Use wireless networks"

iOS 快速将我的位置按钮移动到右上角

Java GUI基本登录与MySQL报告错误的登录信息

java - queryIntentActivities() 采用什么标志?

android - 使用 Google Play 服务位置在 android 中唤醒过多的警报管理器

java - 在 CMD 中运行时出现 ClassNotFoundException

java - 不基于 JNI 的 Android 共享库