Instead of dynamic registration, I want to statically register my receiver. For dynamic registration, it works well, I was using this :
..
static private IntentFilter GPSActionFilter;
..
GPSActionFilter = new IntentFilter("GGPS Service");
context.registerReceiver(GPSActionReceiver, GPSActionFilter);
..
static private BroadcastReceiver GPSActionReceiver = new BroadcastReceiver(){
public void onReceive(Context context, Intent intent) { ..}
For static registration, debugger never hits the onReceive function, I am using this:
In AndoridManifest :
<receiver android:name="LocationListener$GPSActionReceiver" >
<intent-filter>
<action android:name="LocationListener.ACTION_GPS_SERVICE" />
</intent-filter>
</receiver>
In code :
public class LocationListener extends BroadcastReceiver
{
public static IntentFilter GPSActionFilter;
public static final String ACTION_GPS_SERVICE = "com.example.LocationListener.GPSActionFilter";
public static BroadcastReceiver GPSActionReceiver;
public void onReceive(final Context context, final Intent intent)
{..}
}
First, you cannot have a
private
BroadcastReceiver
in the manifest, as Android needs to be able to create an instance of it. Please make this public.Second, the syntax for the name of static inner classes is
LocationListener$GPSActionReceiver
, notLocationListener.GPSActionReceiver
.When declaring an intent-filter action in the manifest, the android:name must be a string literal and can not access Strings from classes. Also, I recommend you prepend your fully qualified package name to the intent action ie:
Then change
To