gpt4 book ai didi

java - NETWORK_PROVIDER 无法在 Android 中工作

转载 作者:行者123 更新时间:2023-12-01 06:38:01 26 4
gpt4 key购买 nike

我为用户构建应用程序以获取最后位置或当前位置。我同时使用 NETWORK_PROVIDERGPS_PROVIDERNETWORK_PROVIDER 没有什么问题。

1.当我在 Micromax 单元 2 中使用 NEWTWORK_PROVIDER 时,应用程序崩溃,而当我使用 GPS_PROVIDER 时,应用程序运行良好。在使用这两个提供商的同时,相同的应用程序在三星和 XIOMI 设备中运行良好。这背后有什么原因吗?

  • NETWORK_PROVIDER 仅支持有限版本吗?

  • 如果某些设备不支持 NETWORK_PROVIDER,那么我该如何在没有 GPS 的情况下获取当前位置?

  • 这是我的代码:

        private void beginAcquiringLocation() {

    //Log.d(TAG, "Beginning location acquisition");
    logStatus("Requesting location update.");

    // we don't want to be killed while handling data transmission in another thread
    // to guarantee we don't take an eternal lock even in case of bugs, set a timeout
    acquireWakeLock(WAKELOCK_TIME_DEFAULT);

    LocationManager locationManager =(LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    Criteria crit = new Criteria();
    String provider = locationManager.getBestProvider(crit, false);
    Location location = locationManager.getLastKnownLocation(provider);

    Log.d("LOCATION>>>>>>>>>>>", String.valueOf(location));

    Log.d("Provider---------->>>>>>>>", provider);
    // no significant time or distance minima, we'll decide if it's usable when we get a coord
    locationManager.requestLocationUpdates(provider, 500, 0, this);

    if(String.valueOf(location).equals("null")){

    locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 500, 0, this);
    Location l=locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
    Log.d("-------Location default----->>>>>>>", String.valueOf(l));


    }
    // next action in process is in the callback upon receiving a location update

    // to prevent endless listening if no updates are ever received, we need to schedule a timeout
    timeoutHandler.removeCallbacks(timeoutTask);
    timeoutHandler.postDelayed(timeoutTask, timeoutDelay);
    }

    最佳答案

    1. Micromax Unit 2 有 A-GPS,所以如果应用程序崩溃就会很奇怪:您有更多关于此的日志吗?
    2. 对我来说,有3种情况:
    1. gps –> (GPS, AGPS) Requires the permission android.permission.ACCESS_FINE_LOCATION.
    2. network –> (AGPS, CellID, WiFi MACID) Requires either of the permissions android.permission.ACCESS_COARSE_LOCATION or android.permission.ACCESS_FINE_LOCATION.
    3. passive –> (CellID, WiFi MACID) Requires the permission android.permission.ACCESS_FINE_LOCATION, although if the GPS is not enabled this provider might only return coarse fixes.

    如果您需要更多信息,可以引用:http://developerlife.com/tutorials/?p=1375

    关于java - NETWORK_PROVIDER 无法在 Android 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32139755/

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