在项目终需要开启gps用来获取地理位置,获取不到地理位置时发送一条广播,进行通知
1,启动服务,在服务中每隔3秒检测gps是否开启以及获取到当前的地理位置
2,将获取到的地理位置发送一条全局广播,便于接收
public class LocationService extends Service implements LocationListener {
private String cityName; //当前城市名称
private LocationManager locationManager;
private Context context;
//接收并且处理消息
private Handler handler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message msg) {
if (msg.what == 1) {
// Log.e("---", "获取到地理位置" + cityName);
Intent intent = new Intent("com.city");
intent.putExtra("address", cityName);
context.sendBroadcast(intent);
}
return false;
}
});
private Runnable runnable = new Runnable() {
@Override
publ