I think the problem is how you define you Intent / PendingIntent. There are two ways to start an Activity using Intent, and the code you included looks like a cross between them.
The standard way to start an Activity is to use the Intent constructor, which takes the current context and the Activity class, and use the getActivity method on the PendingIntent to create the PendingIntent:
Intent intent = new Intent(this, ProximityAlert.class); PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
Alternatively, you can add an IntentReceiver to your activity in the manifest using an IntentFilter that listens for a specific action (for example, "eu.mauriziopz.gps.ProximityAlert"). However, in this case, you need to use PendingIntent.getBroadcast to create the PendingIntent.
Intent intent = new Intent("eu.mauriziopz.gps.ProximityAlert"); PendingIntent pIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
In all cases, you need to make sure that you have the correct permissions for the location-based services defined in your manifest:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.INTERNET"/>
Alternatively, instead of using the string "gps", you can use the static constant LocationManager.GPS_PROVIDER .
source share