Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;

import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.NotificationCompat;

public class Main {
    public static final int NOTIFICATION_ID = 20111;

    public static void notifyShort(@NonNull Context context, @NonNull String title, @NonNull String msg,
            @DrawableRes int iconId) {
        notifyShort(context, title, msg, iconId, NOTIFICATION_ID, null);
    }

    public static void notifyShort(@NonNull Context context, @NonNull String title, @NonNull String msg,
            @DrawableRes int iconId, @NonNull PendingIntent pendingIntent) {
        notifyShort(context, title, msg, iconId, NOTIFICATION_ID, pendingIntent);
    }

    public static void notifyShort(@NonNull Context context, @NonNull String title, @NonNull String msg,
            @DrawableRes int iconId, int nId) {
        notifyShort(context, title, msg, iconId, nId, null);
    }

    public static void notifyShort(@NonNull Context context, @NonNull String title, @NonNull String msg,
            @DrawableRes int iconId, int nId, @Nullable PendingIntent pendingIntent) {
        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notification = new NotificationCompat.Builder(context).setAutoCancel(true)
                .setDefaults(Notification.DEFAULT_ALL).setContentTitle(title).setContentText(msg)
                .setSmallIcon(iconId).setContentIntent(pendingIntent).build();
        notificationManager.notify(nId, notification);
    }

    public static void notifyShort(@NonNull Context context, @NonNull String title, String msg,
            @DrawableRes int iconId, @NonNull NotificationCompat.Action action) {
        notifyShort(context, title, msg, iconId, action, NOTIFICATION_ID);
    }

    public static void notifyShort(@NonNull Context context, @NonNull String title, String msg,
            @DrawableRes int iconId, @NonNull NotificationCompat.Action action, int nId) {
        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notification = new NotificationCompat.Builder(context).setAutoCancel(true)
                .setDefaults(Notification.DEFAULT_ALL).setContentTitle(title).setContentText(msg)
                .setSmallIcon(iconId).addAction(action).setContentIntent(action.actionIntent).build();
        notificationManager.notify(nId, notification);
    }
}