The push notification displays an action / popup, not a message in the status bar

I am new to android and I really need your help. In the push notification (GCMintentservice) I receive material using pending intentions. but I want to show a popup or action instead of a push notification message in the status bar. That is, if the application is running, the user will have displayed activity, and NOT in the status bar. I know this is not recommended. But is it possible? Any help is appreciated.

Thanks in advance

+5
source share
1 answer

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" /> 
+1
source

Source: https://habr.com/ru/post/1202420/


All Articles