You can use context.getSystemService(Context.LOCATION_SERVICE);
It works in your activity with the this
keyword because your activity is a context.
Luckily you have a context object passed to your onReceive
, just use that.
@Override
public void onReceive(Context context, Intent intent) {
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
// whatever you need to do
}