Is their a way to start a service as a foreground service and hide the notification while an activity is visible?
Consider a music player, while the app is opened, you d
Use following steps:
1.Use ActivityManager to get current package name(i.e the Activity Running on top).
2.check if its your application then do not show the notifications
3.else If it is not your application then show the notifications.
ActivityManager manager =(ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List tasks = manager.getRunningTasks(1);
String topActivityName = tasks.get(0).topActivity.getPackageName();
if(!(topActivityName.equalsIgnoreCase("your package name"))){
//enter notification code here
}