当手机靠近某个位置时,我正在尝试获取和更新。我都尝试过使用 addProximityAlert 和 requestLocationUpdates
LocationManager lm =(LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location l = lm.getLastKnownLocation("gps");
Intent intent = new Intent("eu.mauriziopz.gps.ProximityAlert");
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
lm.addProximityAlert(12, 12, 100, 1000000, pIntent);
这个永远不会触发意图(我知道这是有效的,因为我可以手动触发它)。我尝试使用监听器,但它只执行一次。无论我更新 gps 多少次,它都不会再被调用
ProximityListener pl = new ProximityListener();
lm. requestLocationUpdates("gps", 2000, 10, pl);
这是活动的代码(在第一种情况下调用)
public class ProximityAlert extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Log.d("intent", "Hi");
finish();
}
这是监听器
public class ProximityListener implements LocationListener {
String DEBUG_TAG = "ProximityListener";
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
Log.d(DEBUG_TAG, location.toString());
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
谢谢