@Override
public
int
onStartCommand(Intent intent,
int
flags,
int
startId) {
Log.d(TAG,
"onStartCommand Called."
);
int
restart = intent.getIntExtra(
"restart"
,
0
);
switch
(restart) {
case
1
:
locationList = (HashMap<Integer, PendingIntent>) intent.getSerializableExtra(
"locationList"
);
Log.d(TAG,
"LocationList : "
+ locationList);
break
;
}
locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
int
size = locationList.size();
Log.d(TAG,
"Size : "
+ size);
id = intent.getIntExtra(
"id"
,
0
);
lat = intent.getDoubleExtra(
"lat"
,
0.0
);
lng = intent.getDoubleExtra(
"lng"
,
0.0
);
radius = intent.getFloatExtra(
"radius"
,
0
);
expiration = intent.getLongExtra(
"expiration"
,
0
);
type = intent.getIntExtra(
"type"
,
2
);
switch
(type){
case
0
:
register(id, lat, lng, radius, expiration);
break
;
case
1
:
deleteLocation(id);
break
;
}
return
Service.START_REDELIVER_INTENT;
}
public
void
register(
int
id,
double
lat,
double
lng,
float
radius,
long
expiration){
Log.d(TAG,
"id : "
+ id +
", lat : "
+ lat +
", lng : "
+ lng +
", radius : "
+ radius +
", expiration : "
+ expiration);
Intent proximityIntent =
new
Intent(
"org.jsb.busgod.busgod"
);
proximityIntent.setAction(
"org.jsb.busgod.busgod"
);
proximityIntent.putExtra(
"id"
,id);
pendingIntent = PendingIntent.getBroadcast(
this
,id,proximityIntent,PendingIntent.FLAG_CANCEL_CURRENT);
locationManager.addProximityAlert(lat,lng,radius,expiration,pendingIntent);
locationList.put(id, pendingIntent);
}