标题全部说出来,我正在使用这个:
public int onStartCommand(Intent get,int num1,int num2){
if (lm != null){
lm.removeUpdates(this);
}
prefs = getSharedPreferences("Prefs",
Context.MODE_PRIVATE);
lm = (LocationManager) this.getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy( Criteria.ACCURACY_COARSE );
String provider = lm.getBestProvider( criteria, false );
////* Just GPS is Listed in this List , Google Location is Enabled but Not Detected
/*and Note the Parameter 'false' to get the list of all avaible provider,enable or not
Toast.makeText(this, provider, Toast.LENGTH_LONG).show(); */
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 10000, 0, this);
if(IsFromWidget != true){
str2 = get.getStringExtra("num");
}
CheckNetworkState();
return 0;
}
public void onDestroy()
{
super.onDestroy();
if (lm != null){
lm.removeUpdates(this);
}
}
private void CheckNetworkState() {
if (lm != null){
lm.removeUpdates(this);
}
stopSelf();
}
}
public void onLocationChanged(Location arg0) {
// TODO Auto-generated method stub
lat = arg0.getLatitude();
lon = arg0.getLongitude();
if (lat == 0 && lon == 0){
}
}
}
if(IsFromWidget = true){
if (lat == 0 && lon == 0){
}
}
stopSelf();
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
}
但它只返回 GPS 和我的谷歌位置设置已启用,并且我连接了 3G 或 Wifi,当我使用 Android 2.3.x 时它工作正常,请不要注意代码错误,我在发布之前编辑了代码在这里。
谢谢 。