I am an android newbie and i really need your help .On push notification (GCMintentservice) i get to do stuff using pending intent. but I want to show a popup or an activity instead of a push notification message in status bar. That is if the app is running the user will have an activity displayed and NOT a message on status bar. I know its not recommended. But is that possible? Any help is appreciated.
Thanks in advance
Yes! it is possible. On receiving push message from GCM, use 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 come to know if your app is foreground or background. If it is background, show a notification else show an AlertDialog
.
Above method needs this permission:
<uses-permission android:name="android.permission.GET_TASKS" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With