Bonjour tout l'monde =)

Je me suis créé un programme assez simple qui affiche après appui sur un bouton les coordonnées GPS actuelles de l'apareil.
Pour cela, j'ai donc créé une classe MainActivity avec un listener sur le bouton, et une fois celui-ci "clické" donc, il apelle une nouvelle instance de mon Asynctask qui implémente l'interface LocationListener.

Le truc c'est que j'obtiens bien des coordonnées gps, mais ces dernières ne changent jamais (même en me déplaçant jusqu'à ma rue..Pire ! même lorsque j'éteind/rallume mon téléphone). Donc en trifouillant un peu, je me suis rendu compte que la méthode onLocationChanged n'est en fait jamais appelé dans mon programme (pas de trace dans mon LogChat..).

Donc j'aimerais tout simplement comprendre pourquoi ^^ pourquoi elle n'est jamais appelée.
J'ai également testé autre chose, j'ai téléchargé le projet de cette adresse qui 'à priori' devrait fonctionner hors l'application boucle en "chargement" sans jamais afficher de coordonnées... Alors je suis en train de me demander si le problème ne serait pas propre à mon appareil...

Voici mon code, j'ai peut être oublié quelque chose dedans ?

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
 
public class MainActivity extends Activity {
 
	public static Context context;
	public Button push = null;
	public getGPS tache_getGPS = null;
 
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		context = getApplication().getApplicationContext();
 
		push = (Button) findViewById(R.id.button);
		push.setOnClickListener(new OnClickListener() {
 
			@Override
			public void onClick(View v) {
				Log.i("T: onClick", "debut");
				tache_getGPS = new getGPS();
				tache_getGPS.execute();
				Log.i("T: onClick", "fin");
				// TODO Auto-generated method stub
			}
		});
	}
 
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
 
}
 
class getGPS extends AsyncTask<Void, Integer, Location> implements
		LocationListener {
 
	final long REFRESH = 5 * 1000;
	private Location location;
	private LocationManager lm;
 
	protected void onPreExecute() {
		Log.i("T: onPreExcute", "debut");
		Criteria crit = new Criteria();
		crit.setAccuracy(Criteria.ACCURACY_FINE);
 
		// Configure location manager - I'm using just the network provider in
		// this example
		lm = (LocationManager) MainActivity.context
				.getSystemService(Context.LOCATION_SERVICE);
 
		String best = lm.getBestProvider(crit, false);
		Log.i("T: onPreExecute", "best : " + best);
 
		lm.requestLocationUpdates(best, 0, 1, this);
		location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
		// nearProgress.setVisibility(View.VISIBLE);
		Log.i("T: onPreExcute", "fin");
	}
 
	protected Location doInBackground(Void... params) {
		Log.i("T: doInBackground", "debut");
 
		// Try to use the last known position
		Location lastLocation = lm
				.getLastKnownLocation(LocationManager.GPS_PROVIDER);
		/*
		 * // If it's too old, get a new one by location manager if
		 * (System.currentTimeMillis() - lastLocation.getTime() > REFRESH) {
		 * while (location == null) try { Thread.sleep(100); } catch (Exception
		 * ex) { }
		 * 
		 * return location; }
		 */
		Log.i("T: doInBackground", "fin");
		return lastLocation;
	}
 
	protected void onPostExecute(Location location) {
		Log.i("T: onPostExecute", "debut");
		// nearProgress.setVisibility(View.GONE);
 
		lm = (LocationManager) MainActivity.context
				.getSystemService(Context.LOCATION_SERVICE);
		lm.removeUpdates(this);
 
		Log.i("T: onPostExecute",
				"Altitude : " + String.valueOf(location.getAltitude()));
		Log.i("T: onPostExecute",
				"Longitude : " + String.valueOf(location.getLongitude()));
		Log.i("T: onPostExecute",
				"Latitude : " + String.valueOf(location.getLatitude()));
		Log.i("T: onPostExecute",
				"Precision(mètre) : " + String.valueOf(location.getAccuracy()));
		Log.i("T: onPostExecute", "fin");
 
		Toast.makeText(
				MainActivity.context,
				"Altitude : " + String.valueOf(location.getAltitude()) + "\n"
						+ "Longitude : "
						+ String.valueOf(location.getLongitude()) + "\n"
						+ "Latitude : "
						+ String.valueOf(location.getLatitude()) + "\n"
						+ "Precision(mètre) : "
						+ String.valueOf(location.getAccuracy()),
				Toast.LENGTH_SHORT).show();
 
		return;
	}
 
	@Override
	public void onLocationChanged(Location newLocation) {
		Log.i("T: onLocationChanged", "debut");
		location = newLocation;
		Log.i("T: onLocationChanged", "fin");
	}
 
	@Override
	public void onProviderDisabled(String provider) {
		Log.i("T: onProviderDisabled", provider);
	}
 
	@Override
	public void onProviderEnabled(String provider) {
		Log.i("T: onProviderEnabled", provider);
	}
 
	@Override
	public void onStatusChanged(String provider, int status, Bundle extras) {
		Log.i("T: onStatusChanged", "provider : " + provider);
		Log.i("T: onStatusChanged", "status : " + status);
		Log.i("T: onStatusChanged", "extras : " + extras.toString());
	}
 
}
Comme vous pouvez le voir, il y a une boucle while mis en commentaire. Si je décommente cette dernière, mon application tourne en boucle sans afficher les coordonnées gps (comportement similaire au programme que j'ai déniché sur Internet..).
Et au cas où, voici mon manifest :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.testgps"
    android:versionCode="1"
    android:versionName="1.0" >
 
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
 
    <uses-permission android:name="android.permission.ACCESS_GPS" />
    <uses-permission android:name="android.permission.ACCESS_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />
 
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.testgps.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
 
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
 
</manifest>
Merci d'avance pour votre aide =)