com.andrewchelladurai.simplebible.utilities.NotificationDisplayer.java Source code

Java tutorial

Introduction

Here is the source code for com.andrewchelladurai.simplebible.utilities.NotificationDisplayer.java

Source

/*
 *
 * This file 'NotificationDisplayer.java' is part of SimpleBible :
 *
 * Copyright (c) 2016.
 *
 * This Application is available at below locations
 * Binary : https://play.google.com/store/apps/developer?id=Andrew+Chelladurai
 * Source : https://github.com/andrewchelladurai/
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * OR <http://www.gnu.org/licenses/gpl-3.0.txt>
 *
 */

package com.andrewchelladurai.simplebible.utilities;

import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.support.v4.app.NotificationCompat;
import android.util.Log;

import com.andrewchelladurai.simplebible.R;
import com.andrewchelladurai.simplebible.SimpleBibleActivity;

/**
 * Created by Andrew Chelladurai - TheUnknownAndrew[at]GMail[dot]com on 17-Nov-2016 @ 6:09 PM
 */
public class NotificationDisplayer extends BroadcastReceiver {

    private static final String TAG = "SB_AlarmReceiver";

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d(TAG, "onReceive: called");
        long when = System.currentTimeMillis();
        int MID = (int) when;
        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);

        Intent notIntent = new Intent(context, SimpleBibleActivity.class);
        notIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.ic_notification_small_icon)
                .setContentTitle(context.getString(R.string.application_name))
                .setContentText(context.getString(R.string.notification_text)).setSound(alarmSound)
                .setAutoCancel(true).setWhen(when).setContentIntent(pendingIntent);

        notificationManager.notify(MID, builder.build());
        Log.d(TAG, "onReceive: reminder Created");
    }
}