簡體   English   中英

檢查網絡位置提供程序是否已啟用的任何其他方法?

[英]Any alternative way to check if network location provider is enabled?

當我檢查

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());
}

你也可以嘗試這樣:

public boolean isDataConnectionAvailable(Context context){
        ConnectivityManager connectivityManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo info = connectivityManager.getActiveNetworkInfo();
        if(info == null)
            return false;

        return connectivityManager.getActiveNetworkInfo().isConnected();
}

public boolean isGpsEnabled(LocationManager manager){
        if ( !manager.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) {
            return false;
        }
        return true;
}

public boolean isLocationByNetworkEnabled(LocationManager manager){
        if ( !manager.isProviderEnabled( LocationManager.NETWORK_PROVIDER ) ) {
            return false;
        }
        return true;
}

列表中的提供者是否由getProviders返回(true); 還有? 也許該設備認為應始終啟用網絡位置提供程序以提供PASSIVE_PROVIDER? 似乎打破了我。 您認為哪種三星設備出現此問題?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM