I want from the “class gps_Listener” create “Intent” and send parameters in “class LocationChangedReceiver”
my class gps_Listener
public class gps_Listener implements LocationListener {
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
send("I found the location");
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
public void send(String str) {
Intent intent = new Intent("logGPS");
intent.putExtra("Message", str);
sendBroadcast(intent); //- without context does not work
}
}
and class LocationChangedReceiver
public class LocationChangedReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
}
}
I do not know how to do, as you can see there is no “Context”
You can pass a context to your listener when you create it.
So you can use it in your send method:
Create it that way:
Remember to register your broadcast receiver in the manifest (you could also un/register dynamically):