Yes! perhaps. When receiving a push message from GCM, use the following method:
public boolean isForeground(String myPackage) { ActivityManager manager = (ActivityManager) ctx .getSystemService(Activity.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> runningTaskInfo = manager .getRunningTasks(1); ComponentName componentInfo = runningTaskInfo.get(0).topActivity; if (componentInfo.getPackageName().equals(myPackage)) return true; return false; }
You will find out if your application is front or background. If it's a background, show the notification again, show AlertDialog .
The above method needs this permission:
<uses-permission android:name="android.permission.GET_TASKS" />
source share