Location Manager not working in Android 4.0.2 Emulator

萝らか妹 提交于 2019-12-06 02:32:02
Bobs

this is an issue. look at this.

It says:

Do not use direct provider strings, as it is not guaranteed that it will exist at runtime.

Use only providers that you get from the LocationManager, like this:

    LocationManager locationManager = (LocationManager)context.getSystemService( Context.LOCATION_SERVICE );

    Criteria criteria = new Criteria();
    criteria.setAccuracy( Criteria.ACCURACY_COARSE );
    String provider = locationManager.getBestProvider( criteria, true );

    if ( provider == null ) {
        Log.e( TAG, "No location provider found!" );
        return;
    }

    lastLocation = locationManager.getLastKnownLocation(provider);

or

Another useful method in locationmanager is LocationManager.getAllProviders()

/**
 * Returns a list of the names of all known location providers.  All
 * providers are returned, including ones that are not permitted to be
 * accessed by the calling activity or are currently disabled.
 *
 * @return list of Strings containing names of the providers
 */
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!