Android : Android show Notification when app is not open?

on Tuesday, October 7, 2014


Is it possisble to only display a notification to the user when the app is not active. (Open but not active). At the moment, i have the following code, which displays a notification. However it is also displayed when the user is in the app, and that is kind of pointless.'



public void notifyNewOrders() {
sp.play(soundId2, 1, 1, 0, 0, 1);
int notificationId = 001;
Intent viewIntent = new Intent(this, ListActivity.class);
viewIntent.putExtra("01", "12");
PendingIntent viewPendingIntent = PendingIntent.getActivity(this, 0,
viewIntent, 0);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(
this)
.setSmallIcon(R.drawable.coffee_tea_icon)
.setContentTitle("New Orders available!")
.setContentText(
"New orders are available. Want to make some easy money?")
.setContentIntent(viewPendingIntent);
NotificationManagerCompat notificationManager = NotificationManagerCompat
.from(this);
notificationManager.notify(notificationId, notificationBuilder.build());
}


Could i check if the activity is being viewed. And if not, display the notification? How can this be done. Thank you.


0 comments:

Post a Comment