com.pnsofts.itebooksinfo.Utils.NotificationHelper.java Source code

Java tutorial

Introduction

Here is the source code for com.pnsofts.itebooksinfo.Utils.NotificationHelper.java

Source

/*******************************************************************************
 * Copyright (c) 2012 Manning
 * See the file license.txt for copying permission.
 ******************************************************************************/
package com.pnsofts.itebooksinfo.Utils;

import android.R;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;

public class NotificationHelper {

    public static final int NOTIFICATION_ID = 2;

    public static void showMsgNotification(Context ctx, String title, String filePath) {
        final NotificationManager mgr;
        mgr = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx)
                .setSmallIcon(R.drawable.ic_dialog_info).setTicker(title).setContentTitle(title)
                .setContentText(filePath);

        mgr.notify(NOTIFICATION_ID, builder.build());
    }

    public static void dismissMsgNotification(Context ctx) {
        final NotificationManager mgr;
        mgr = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
        mgr.cancel(NOTIFICATION_ID);
    }

}