我有一个应用程序,它使用网络提供程序的位置.每次应用程序启动时,它都会检查是否使用LocationManager中的isProviderEnabled()方法启用了网络提供程序.如果返回false,则向用户发出警报以启用网络提供程序,然后使用该应用程序.这个逻辑一直运行得非常好,除了一些非例外的非Google认证设备(因为它们通常也没有Maps API).最近,对于ICS上的一些设备,现在在JellyBean模拟器上,即使启用了isProviderEnabled(),我也会得到一致的"假".
我已经转移到使用从Settings.Secure.getString(getContentResolver(),Settings.Secure.LOCATION_PROVIDERS_ALLOWED)返回的字符串,以查看它是否包含"网络".这是一个黑客,但它现在正在工作.我希望能够使用isProviderEnabled()方法.
以前有人看过这个问题吗?
我正在尝试使用LocationManager和LocationListener来获取android中的当前位置,如http://developer.android.com/guide/topics/location/obtaining-user-location.html中所述.
但是,从不调用LocationListener的onLocationChanged方法.我使用了一个真正的Android手机/也使用了模拟器和使用telnet更改的模拟位置,如上面的链接所述.
这是我的代码:
public class MyActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/* Use the LocationManager class to obtain GPS locations */
LocationManager mlocManager = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
LocationListener mlocListener = new CustomLocationListener(
getApplicationContext());
// Location Providers
String locationProvider = LocationManager.NETWORK_PROVIDER;
// LocationProvider locationProvider = LocationManager.GPS_PROVIDER;
mlocManager
.requestLocationUpdates(locationProvider, 0, 0, mlocListener);
}
}
Run Code Online (Sandbox Code Playgroud)
和我的LocationListener:
public class CustomLocationListener implements LocationListener {
private Context m_context;
public CustomLocationListener(Context context) {
m_context = context;
}
@Override
public void …Run Code Online (Sandbox Code Playgroud)