Android 安卓GPS不再工作了

Android 安卓GPS不再工作了,android,gps,Android,Gps,我在HTC Desire S上玩GPS,并制作了一个非常小的地图应用程序。它工作得很好,直到我偶然发现。 我再次卸载了它,现在我的GPS不再工作了。我知道有固定的时间,但是 locManager.isProviderEnabled(LocationManager.GPS_PROVIDER) 始终返回true,并且应用程序不再请求位置更新 GPSMapTrackerService.java: package net.hobbycoder.android.gpsmap; import andro

我在HTC Desire S上玩GPS,并制作了一个非常小的地图应用程序。它工作得很好,直到我偶然发现。 我再次卸载了它,现在我的GPS不再工作了。我知道有固定的时间,但是

locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
始终返回true,并且应用程序不再请求位置更新

GPSMapTrackerService.java:

package net.hobbycoder.android.gpsmap;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.IBinder;
import android.widget.Toast;

public class GPSMapTrackerService extends Service implements LocationListener {

    private Resources res;
    private FileManager fileManager;
    private LocationManager locManager;
    private boolean showNotification = true;

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        res = getResources();
        fileManager = new FileManager(getApplicationContext());
        locManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
        //GPS on?
        if(!locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
            Toast.makeText(this, res.getString(R.string.noGPSText), Toast.LENGTH_LONG).show();
            showNotification = false;
            stopSelf();
        }
        else{
            showNotification = true;
        }
    }

    @Override
    public void onStart(Intent intent, int startID) {
        locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
        if(showNotification)
            Toast.makeText(this, res.getString(R.string.startedText), Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onDestroy() {
        locManager.removeUpdates(this);
        if(showNotification)
            Toast.makeText(this, res.getString(R.string.stoppedText), Toast.LENGTH_SHORT).show();
    }

    public void onLocationChanged(Location loc) {
        fileManager.write(loc.getLatitude() + ":" + loc.getLongitude() + ";");
    }

    public void onProviderDisabled(String provider) {

    }

    public void onProviderEnabled(String provider) {

    }

    public void onStatusChanged(String provider, int status, Bundle extras) {

    }
}
似乎位置被卡住了,因为我的时钟小部件下的文本显示我在纽约,但我在德国

也不起作用,所以问题不应该出现在我的代码中

希望任何人都能提供帮助:(

已被弃用,如果您阅读了首选文档,您会发现根据您的API,甚至可能不会调用onStart()

尝试将onStart()更改为onStartCommand():

另外您从未在任何重写的方法中调用
super
函数。请更新所有方法(onBind()除外,它不执行任何操作):


尝试使用该应用程序清除GPS数据并重新下载。我目前没有该应用程序,但它位于菜单选项中的某个位置。

好的,谢谢提示。但它仍然不起作用。似乎位置被卡住了(请参见问题)。嗯,你打开模拟位置了吗?(设置->应用程序->开发->允许模拟位置)我关闭了它,重新启动了我的设备,但它仍然不工作。好的,重新阅读开发人员的应用程序描述,其中有一节是关于禁用“使用无线网络”的,因为它无意中保留了假位置。小部件现在显示了真实位置,但GPS应用程序仍然没有请求更新
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
    if(showNotification)
        Toast.makeText(this, res.getString(R.string.startedText), Toast.LENGTH_SHORT).show();
}
@Override
public void onCreate() {
    super.onCreate();
    ...

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
    if(showNotification)
        Toast.makeText(this, res.getString(R.string.startedText), Toast.LENGTH_SHORT).show();
    return super.onStartCommand(intent, flags, startId);
}

// etc, etc