gpt4 book ai didi

Android 模拟 gps 供应商

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:12:12 32 4
gpt4 key购买 nike

我的代码 fragment 是:

mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if(mLocationManager.getProvider(LocationManager.GPS_PROVIDER) != null) {
mLocationManager.removeTestProvider(LocationManager.GPS_PROVIDER);
}

mLocationManager.addTestProvider(LocationManager.GPS_PROVIDER,
"requiresNetwork" == "", "requiresSatellite" == "",
"requiresCell" == "", "hasMonetaryCost" == "",
"supportsAltitude" == "", "supportsSpeed" == "",
"supportsBearing" == "",

android.location.Criteria.POWER_LOW,
android.location.Criteria.ACCURACY_FINE);

location = new Location(LocationManager.GPS_PROVIDER);

mLocationManager.setTestProviderEnabled(
LocationManager.GPS_PROVIDER, true);

// mLocationManager.setTestProviderLocation(LocationManager.GPS_PROVIDER,
// location);

location.setLatitude(FinalLatitudeIntArray[0]);
location.setLongitude(FinalLongitudeIntArray[0]);
mLocationManager.setTestProviderLocation(
LocationManager.GPS_PROVIDER, location);

我收到错误:

java.lang.IllegalArgumentException: Provider "gps" unknown
at android.os.Parcel.readException(Parcel.java:1326)
at android.os.Parcel.readException(Parcel.java:1276)
at android.location.ILocationManager$Stub$Proxy.removeTestProviderEnabled(ILocationManager.java:1097)
at android.location.LocationManager.removeTestProviderEnabled(LocationManager.java:1130)

请帮我解决这个错误。加上。之前应用程序运行良好,但当我重新启动系统时,应用程序开始显示错误。

最佳答案

来自位置管理器上的 Android 文档:

removeTestProvider() throws 
IllegalArgumentException if no provider with the given name exists

因此,如果您在模拟器上进行测试,则 GPS 的设置可能已因重启而重置(尝试检查您的权限和 DDMS 以再次启用它)。如果在设备上,您必须禁用 GPS(转到“设置”并启用 GPS)。

编辑:找到相关内容:here .基本上,模拟器中发生了一些看起来不稳定的事情。从该线程的评论中,尝试使用 Criteria.ACCURACY_FINE 而不是 LocationManager.GPS_PROVIDER,例如:

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

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

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

浏览该线程以获取更多信息。

关于Android 模拟 gps 供应商,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13549701/

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