Yes, it is quite possible if I correctly interpret what you ask.
To accomplish this, you will send a GCM push notification to all your users (unless you had a way, on the server side, filter out some of them). Then, in your application, instead of just creating a notification and passing it to the notification manager, you first need to use the LocationManager (or the new LocationServices API) to determine if the user is in the right place, and then simply drop the GCM if it is not.
To do this, you need to take care of a few things:
Your AndroidManifest.xml will require several permission changes, both for GCM changes and for access to location:
<permission android:name="com.myappname.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="com.myappname.permission.C2D_MESSAGE" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
You also need to configure the notification receiver in the <application> section of the manifest:
<receiver android:name="com.myappname.NotificationReceiver" android:permission="com.google.android.c2dm.permission.SEND"> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="com.myappname" /> </intent-filter> <intent-filter> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <category android:name="com.myappname" /> </intent-filter> </receiver>
In addition, you need to write your NotificationReceiver java code class and override the onReceive function:
public class NotificationReceiver extends BroadcastReceiver { public void onReceive(final Context context, final Intent intent) { if ("com.google.android.c2dm.intent.REGISTRATION".equals(intent.getAction())) { handleRegistration(context, intent);
source share