HTC Desire S で GPS をいじっていて、非常に小さな地図アプリケーションを作成しました。このアプリに出くわすまでは、非常にうまく機能していました。再度アンインストールしたところ、GPS が機能しなくなりました。修正時間があることは知っていますが、
locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
ALWAYS は 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) {
}
}
時計ウィジェットの下のテキストには、ニューヨークにいるのにドイツにいると表示されているため、場所が動かなくなったようです。
このアプリも機能していないため、問題は私のコードにはありません。
誰かが助けてくれることを願っています:(