Example usage for android.app Notification DEFAULT_ALL

List of usage examples for android.app Notification DEFAULT_ALL

Introduction

In this page you can find the example usage for android.app Notification DEFAULT_ALL.

Prototype

int DEFAULT_ALL

To view the source code for android.app Notification DEFAULT_ALL.

Click Source Link

Document

Use all default values (where applicable).

Usage

From source file:com.nkc.education.service.NotificationHelper.java

/**
 * Basic Text Notification with Ongoing flag enabled for Task Butler, using NotificationCompat
 *
 * @param context/*from   www.j a v  a  2 s . c o  m*/
 * @param id      id of task, call task.getID() and pass it to this parameter
 * @deprecated Use sendBasicNotification for all notifications
 */
public void sendPersistentNotification(Context context, Task task) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setContentText(task.getNotes())
            .setContentTitle(task.getName())
            .setSmallIcon(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ? R.drawable.ic_exam_name
                    : R.drawable.ic_exam_name)
            .setAutoCancel(true).setContentIntent(getPendingIntent(context, task.getID()))
            .setWhen(System.currentTimeMillis()).setOngoing(true).setDefaults(Notification.DEFAULT_ALL);

    Notification notification = builder.getNotification();
    NotificationManager notificationManager = getNotificationManager(context);
    notificationManager.notify(task.getID(), notification);
}

From source file:zhenma.myapplication.DataLayerListenerService.java

public void btnShowNotificationClick(String friend_id, String name, boolean if_friend) {
    int notificationId = 101;

    // Create an intent for the reply action
    Intent actionIntent = new Intent(this, MainActivity.class);
    if (if_friend) {
        actionIntent.putExtra("methodName", "noAction");
    } else {/*from  ww w  .  j  a  v  a 2  s  .  c o m*/
        actionIntent.putExtra("methodName", "sendAcceptMessage");
    }
    actionIntent.putExtra("friend_id", friend_id);
    actionIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent actionPendingIntent = PendingIntent.getActivity(this, 0, actionIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Create the action
    NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.ic_checked,
            getString(if_friend ? R.string.oldFriendRemind : R.string.acceptButt), actionPendingIntent).build();

    //Building notification layout
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(if_friend ? R.drawable.yellow_handshack : R.drawable.red_handshack)
            .setContentTitle(if_friend ? "Old Friend: " + name : "New Friend Request: " + name)
            .setDefaults(Notification.DEFAULT_ALL).setContentText("Swipe left!")
            .extend(new NotificationCompat.WearableExtender().addAction(action));

    // instance of the NotificationManager service
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);

    // Build the notification and notify it using notification manager.
    notificationManager.notify(notificationId, notificationBuilder.build());
    Log.d("Notification", "Notify Sent!");
}

From source file:org.kde.kdeconnect.Plugins.ReceiveNotificationsPlugin.ReceiveNotificationsPlugin.java

@Override
public boolean onPackageReceived(final NetworkPackage np) {

    if (!np.has("ticker") || !np.has("appName") || !np.has("id")) {
        Log.e("NotificationsPlugin", "Received notification package lacks properties");
    } else {/*from   w w w  . j a v  a 2s  .  c  om*/
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
        stackBuilder.addParentStack(MaterialActivity.class);
        stackBuilder.addNextIntent(new Intent(context, MaterialActivity.class));
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

        Bitmap largeIcon = null;
        if (np.hasPayload()) {
            int width = 64; // default icon dimensions
            int height = 64;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                width = context.getResources()
                        .getDimensionPixelSize(android.R.dimen.notification_large_icon_width);
                height = context.getResources()
                        .getDimensionPixelSize(android.R.dimen.notification_large_icon_height);
            }
            final InputStream input = np.getPayload();
            largeIcon = BitmapFactory.decodeStream(np.getPayload());
            try {
                input.close();
            } catch (Exception e) {
            }
            if (largeIcon != null) {
                //Log.i("NotificationsPlugin", "hasPayload: size=" + largeIcon.getWidth() + "/" + largeIcon.getHeight() + " opti=" + width + "/" + height);
                if (largeIcon.getWidth() > width || largeIcon.getHeight() > height) {
                    // older API levels don't scale notification icons automatically, therefore:
                    largeIcon = Bitmap.createScaledBitmap(largeIcon, width, height, false);
                }
            }
        }
        Notification noti = new NotificationCompat.Builder(context).setContentTitle(np.getString("appName"))
                .setContentText(np.getString("ticker")).setContentIntent(resultPendingIntent)
                .setTicker(np.getString("ticker")).setSmallIcon(R.drawable.ic_notification)
                .setLargeIcon(largeIcon).setAutoCancel(true).setLocalOnly(true) // to avoid bouncing the notification back to other kdeconnect nodes
                .setDefaults(Notification.DEFAULT_ALL).build();

        NotificationManager notificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationHelper.notifyCompat(notificationManager, "kdeconnectId:" + np.getString("id", "0"),
                np.getInt("id", 0), noti);

    }

    return true;
}

From source file:com.adkdevelopment.rssreader.data.services.FetchJobService.java

/**
 * Raises a notification each day on news update.
 *///from w  w  w  .j  a v a  2s . c  o m
private void sendNotification() {

    PrefsManager prefsManager = new PrefsManager(getBaseContext());

    Context context = getApplicationContext();
    final String NOTIFICATION_GROUP = "notif_group";
    final int NOTIFICATION_ID_1 = 101;

    if (prefsManager.receiveNotifications()) {
        //checking the last update and notify if it's the first of the day
        if (System.currentTimeMillis() - prefsManager.getLastNotification() >= DateUtils.DAY_IN_MILLIS) {

            Intent intent = new Intent(context, MainActivity.class);

            intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

            PendingIntent pendingIntent = PendingIntent.getActivity(context, NOTIFICATION_ID_1, intent,
                    PendingIntent.FLAG_UPDATE_CURRENT);

            NotificationCompat.Builder builder = new NotificationCompat.Builder(context);

            builder.setDefaults(Notification.DEFAULT_ALL).setAutoCancel(true)
                    .setContentTitle(context.getString(R.string.app_name))
                    .setContentText(context.getString(R.string.articles_notification))
                    .setContentIntent(pendingIntent).setSmallIcon(R.drawable.logo_title)
                    .setTicker(context.getString(R.string.app_name))
                    .setStyle(new NotificationCompat.BigTextStyle()
                            .bigText(context.getString(R.string.articles_notification)))
                    .setGroup(NOTIFICATION_GROUP).setGroupSummary(true);

            NotificationManagerCompat managerCompat = NotificationManagerCompat.from(context);
            managerCompat.notify(NOTIFICATION_ID_1, builder.build());

            prefsManager.setLastNotification();
        }

    }
}

From source file:com.giovanniterlingen.windesheim.controllers.NotificationController.java

void createScheduleChangedNotification() {
    Intent intent = new Intent(ApplicationLoader.applicationContext, ScheduleActivity.class);
    intent.putExtra("notification", true);
    PendingIntent pendingIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext,
            (int) System.currentTimeMillis(), intent, 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ApplicationLoader.applicationContext,
            PUSH_NOTIFICATION_CHANNEL)/*  w  w w  . java 2  s.co m*/
                    .setContentTitle(
                            ApplicationLoader.applicationContext.getResources().getString(R.string.app_name))
                    .setContentText(ApplicationLoader.applicationContext.getResources()
                            .getString(R.string.schedule_changed))
                    .setContentIntent(pendingIntent).setSmallIcon(R.drawable.notifybar).setOngoing(false)
                    .setAutoCancel(true)
                    .setStyle(new NotificationCompat.BigTextStyle().bigText(ApplicationLoader.applicationContext
                            .getResources().getString(R.string.schedule_changed)))
                    .setColor(
                            ContextCompat.getColor(ApplicationLoader.applicationContext, R.color.colorPrimary))
                    .setPriority(NotificationCompat.PRIORITY_HIGH).setDefaults(Notification.DEFAULT_ALL);

    mNotificationManager.notify(SCHEDULE_CHANGED_NOTIFICATION_ID, mBuilder.build());
}

From source file:com.goatappshop.builder.app551fea2e6652a.util.GcmIntentService.java

private void sendNotificationSuccess(Bundle extras) {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, Main.class), 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setDefaults(Notification.DEFAULT_ALL).setSmallIcon(R.drawable.push_icon)
            .setContentTitle(extras.getString("title"))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(extras.getString("message")))
            .setContentText(extras.getString("message"));

    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}

From source file:ti.notifications.TiNotificationsModule.java

@Kroll.method
public void addActionReport(int notificationId, int smallIcon, String title, String message, String summaryText,
        int iconAction, String actionMessage, String className, String packageName) {

    Context context = TiApplication.getInstance().getApplicationContext();
    NotificationCompat.Builder nc = new NotificationCompat.Builder(context);
    NotificationCompat.BigTextStyle bigTextNotification = new NotificationCompat.BigTextStyle();
    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    PendingIntent pendingIntent = pendingIntentLauncherApp(className, notificationId, packageName, summaryText);

    nc.setSmallIcon(smallIcon);/*from  w ww.  j  a  v  a2s . c  o m*/
    nc.setAutoCancel(true);
    nc.setContentTitle(title);
    nc.setContentText(message);

    nc.setDefaults(Notification.DEFAULT_ALL);

    nc.addAction(iconAction, actionMessage, pendingIntent);

    bigTextNotification.setBigContentTitle(title);
    bigTextNotification.bigText(message);
    bigTextNotification.setSummaryText(summaryText);

    nc.setStyle(bigTextNotification);

    nm.notify(notificationId, nc.build());
}

From source file:com.ushahidi.android.app.BackgroundService.java

private void showNotification(String tickerText) {

    // This is what should be launched if the user selects our notification.
    Intent baseIntent = new Intent(this, IncidentTab.class);
    baseIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, baseIntent, 0);

    // choose the ticker text
    newUshahidiReportNotification = new Notification(R.drawable.notification_icon, tickerText,
            System.currentTimeMillis());
    newUshahidiReportNotification.contentIntent = contentIntent;
    newUshahidiReportNotification.flags = Notification.FLAG_AUTO_CANCEL;
    newUshahidiReportNotification.defaults = Notification.DEFAULT_ALL;
    newUshahidiReportNotification.setLatestEventInfo(this, TAG, tickerText, contentIntent);

    if (Preferences.ringtone) {
        // set the ringer
        Uri ringURI = Uri.fromFile(new File("/system/media/audio/ringtones/ringer.mp3"));
        newUshahidiReportNotification.sound = ringURI;
    }//  ww  w .  j  av a 2 s  .  c o  m

    if (Preferences.vibrate) {
        double vibrateLength = 100 * Math.exp(0.53 * 20);
        long[] vibrate = new long[] { 100, 100, (long) vibrateLength };
        newUshahidiReportNotification.vibrate = vibrate;

        if (Preferences.flashLed) {
            int color = Color.BLUE;
            newUshahidiReportNotification.ledARGB = color;
        }

        newUshahidiReportNotification.ledOffMS = (int) vibrateLength;
        newUshahidiReportNotification.ledOnMS = (int) vibrateLength;
        newUshahidiReportNotification.flags = newUshahidiReportNotification.flags
                | Notification.FLAG_SHOW_LIGHTS;
    }

    mNotificationManager.notify(Preferences.NOTIFICATION_ID, newUshahidiReportNotification);
}

From source file:com.dotcom.jamaatAdmin.fcm.GCMListenerService.java

/**
 * Create and show a simple notification containing the received GCM
 * message.//  w w  w .j a  v a  2  s . c  om
 * <p/>
 * <p/>
 * GCM message received.
 */
public void displayNotificationInNotificationBar(Map data) {
    try {
        String messageData = data.get("message").toString();
        int notifyID = Constants.NOTIFICATION_ID;
        //String eData = data.getString("extra_data");
        String message = "";
        if (!TextUtils.isEmpty(messageData)) {
            JSONObject extra_data = new JSONObject(messageData);
            message = extra_data.optString("message");
        }

        // This intent is fired when notification is clicked

        NotificationManager notificationManager = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);

        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        Intent intent;
        String messages = SharedPreferencesManager.getStringPreference("notificationMessage", null);
        if (messages != null && !messages.isEmpty()) {
            messages = message + "," + messages;
            SharedPreferencesManager.setPreference("notificationMessage", messages);

            intent = new Intent(this, NotificationActivity.class);
        } else {
            SharedPreferencesManager.setPreference("notificationMessage", message);

            intent = new Intent(this, NotificationActivity.class);
        }
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        String currentMessages = SharedPreferencesManager.getStringPreference("notificationMessage", null);
        String[] messagesArray = currentMessages.split(",");

        int count = messagesArray.length;
        if (messagesArray.length == 0) {

            notificationManager.cancel(notifyID);
            return;
        }

        final String GROUP_KEY_MESSAGES = "group_key_messages";

        // Group notification that will be visible on the phone
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
        mBuilder.setTicker(getString(R.string.app_name)).setDefaults(Notification.DEFAULT_ALL)
                .setContentTitle(getString(R.string.app_name)).setSound(defaultSoundUri).setAutoCancel(true)
                .setOnlyAlertOnce(false)
                //               .setPriority(Notification.PRIORITY_MAX)
                //               .setOngoing(true)
                //               .setWhen( System.currentTimeMillis() )
                .setContentIntent(pendingIntent).setSmallIcon(R.mipmap.ic_launcher).setGroup(GROUP_KEY_MESSAGES)
                .setGroupSummary(true).build();

        NotificationCompat.Style style;
        if (count > 1) {
            NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
            style = inboxStyle;

            mBuilder.setContentTitle(getString(R.string.app_name));

            for (String r : messagesArray) {
                inboxStyle.addLine(r);
            }
            mBuilder.setContentText(count + " new messages");
            inboxStyle.setBigContentTitle(getString(R.string.app_name));
            inboxStyle.setSummaryText(count + " new messages");
        } else {
            NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
            style = bigTextStyle;

            //            bigTextStyle.setBigContentTitle(messagesArray[0].substring(0, 10).concat(" ..."));
            bigTextStyle.setBigContentTitle(getString(R.string.app_name));
            mBuilder.setContentText(message);
            bigTextStyle.bigText(message);
            //            bigTextStyle.setSummaryText(count + " new event");
        }
        mBuilder.setStyle(style);

        NotificationManagerCompat notificationManager1 = NotificationManagerCompat.from(this);
        notificationManager1.notify(notifyID, mBuilder.build());

    } catch (Exception ex) {

    }
}

From source file:com.snippet.app.NotificationActivity.java

public void onButton4(final View v) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setDefaults(Notification.DEFAULT_ALL)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), android.R.drawable.sym_def_app_icon))
            .setSmallIcon(android.R.drawable.stat_notify_chat).setTicker("Update notification")
            .setContentTitle("Update count when you tap button.")
            .setContentText("ContentText: Hello world! The quick brown fox jumps over the lazy dog.")
            .setSubText("SubText").setNumber(++mCount).setAutoCancel(true);
    Intent resultIntent = new Intent(this, NotificationResultActivity.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(NotificationResultActivity.class);
    stackBuilder.addNextIntent(resultIntent);
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(resultPendingIntent);
    notificationManager.notify(4, builder.build());
}