Example #1
0
 public static void displayNotification(Context context, String text) {
     Intent openIntent = new Intent(context, MainActivity.class);
     Notification notification = new NotificationCompat.Builder(context)
             .setSmallIcon(R.drawable.icon)
             .setContentTitle(context.getResources().getString(R.string.notification_title))
             .setContentText(text)
             .setContentIntent(PendingIntent.getActivity(context, 0, openIntent, 0))
             .addAction(
                     android.R.drawable.ic_menu_close_clear_cancel,
                     context.getResources().getString(R.string.menu_exit),
                     PendingIntent.getBroadcast(context, 0, new ExitIntent(), 0))
             .addAction(
                     android.R.drawable.ic_menu_manage,
                     context.getResources().getString(R.string.menu_main_screen),
                     PendingIntent.getActivity(context, 0, openIntent, 0))
             .build();
     NotificationManager notificationManager =
             (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
     notification.flags |= Notification.FLAG_ONGOING_EVENT;
     notificationManager.notify(1983, notification);
 }
Example #2
0
 private void clearNotification() {
     NotificationManager notificationManager =
             (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
     notificationManager.cancel(1983);
 }