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.sikware.FixMyLife.fcm.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 */// w ww .  j  a v  a 2 s . c  o m
public static void sendNotification(Context context, String messageBody, String channelUrl) {
    Intent intent = new Intent(context, GroupChannelActivity.class);
    intent.putExtra("groupChannelUrl", channelUrl);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0 /* Request code */, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.mipmap.sendbird_ic_launcher)
            .setContentTitle(context.getResources().getString(R.string.app_name)).setContentText(messageBody)
            .setAutoCancel(true).setSound(defaultSoundUri).setPriority(Notification.PRIORITY_MAX)
            .setDefaults(Notification.DEFAULT_ALL).setContentIntent(pendingIntent);

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

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

From source file:com.example.yongwoon.sendbirdtest.fcm.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *//*from  w  ww  .j  a v  a 2 s.co m*/
public static void sendNotification(Context context, String messageBody, String channelUrl) {
    Intent intent = MainActivity_.intent(context).get();
    intent.putExtra("groupChannelUrl", channelUrl);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    PendingIntent pendingIntent = PendingIntent.getActivity(context, 1 /* Request code */, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.mipmap.ic_launcher_round)
            .setContentTitle(context.getResources().getString(R.string.app_name)).setContentText(messageBody)
            .setAutoCancel(true).setSound(defaultSoundUri).setPriority(Notification.PRIORITY_MAX)
            .setDefaults(Notification.DEFAULT_ALL).setContentIntent(pendingIntent);

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

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

From source file:ti.notifications.TiNotificationsModule.java

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

    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);

    nc.setSmallIcon(smallIcon);// w  ww  .  ja v  a 2 s  .  co  m
    nc.setAutoCancel(true);
    nc.setContentTitle(title);
    nc.setContentText(message);

    nc.setDefaults(Notification.DEFAULT_ALL);

    nc.addAction(iconAction, actionMessage, pendingIntentOpenUrl(summaryText));

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

    nc.setStyle(bigTextNotification);

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

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

public void onButton3(final View v) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setDefaults(Notification.DEFAULT_ALL)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher))
            .setSmallIcon(R.drawable.ic_stat_sample).setTicker("Custom icons")
            .setContentTitle("This is a custom icon notification")
            .setContentText("ContentText: Hello world! The quick brown fox jumps over the lazy dog.")
            .setSubText("SubText").setContentInfo("10").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(3, builder.build());
}

From source file:org.dmfs.tasks.notification.NotificationActionUtils.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static void sendDueAlarmNotification(Context context, String title, Uri taskUri, int notificationId,
        long dueDate, boolean dueAllDay, String timezone, boolean silent) {
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    String dueString = "";
    if (dueAllDay) {
        dueString = context.getString(R.string.notification_task_due_today);
    } else {//from w  w  w.  jav a  2s  .c  om
        dueString = context.getString(R.string.notification_task_due_date,
                formatTime(context, makeTime(dueDate, dueAllDay)));
    }

    // build notification
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_notification)
            .setContentTitle(context.getString(R.string.notification_task_due_title, title))
            .setContentText(dueString);

    // color
    mBuilder.setColor(context.getResources().getColor(R.color.colorPrimary));

    // dismisses the notification on click
    mBuilder.setAutoCancel(true);

    // set high priority to display heads-up notification
    if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
        mBuilder.setPriority(Notification.PRIORITY_HIGH);
    }

    // set status bar test
    mBuilder.setTicker(title);

    // enable light, sound and vibration
    if (silent) {
        mBuilder.setDefaults(0);
    } else {
        mBuilder.setDefaults(Notification.DEFAULT_ALL);
    }

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(Intent.ACTION_VIEW);
    resultIntent.setData(taskUri);

    // The stack builder object will contain an artificial back stack for the
    // started Activity.
    // This ensures that navigating backward from the Activity leads out of
    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    // add actions
    if (android.os.Build.VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH) {
        // delay action
        mBuilder.addAction(NotificationUpdaterService.getDelay1dAction(context, notificationId, taskUri,
                dueDate, timezone, dueAllDay));

        // complete action
        NotificationAction completeAction = new NotificationAction(NotificationUpdaterService.ACTION_COMPLETE,
                R.string.notification_action_completed, notificationId, taskUri, dueDate);
        mBuilder.addAction(NotificationUpdaterService.getCompleteAction(context,
                NotificationActionUtils.getNotificationActionPendingIntent(context, completeAction)));
    }

    // set displayed time
    if (dueAllDay) {
        Time now = new Time();
        now.setToNow();
        now.set(0, 0, 0, now.monthDay, now.month, now.year);
        mBuilder.setWhen(now.toMillis(true));
    } else {
        mBuilder.setWhen(dueDate);
    }

    mBuilder.setContentIntent(resultPendingIntent);
    notificationManager.notify(notificationId, mBuilder.build());
}

From source file:com.seb.hhd2k15.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*w  w w.  j  a  va2 s  .co m*/
 */
private void sendNotification(String title, String message) {
    Intent intent = new Intent(this, MainActivity.class);
    Intent intentLieu = new Intent(this, LieuActivity.class);
    intentLieu.putExtra(NAME_LIEU, "Eglise Sainte Jeanne d'Arc");
    intentLieu.putExtra(IMG_1, R.drawable.eglise);

    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    PendingIntent pendingIntentHome = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    PendingIntent pendingIntentLieu = PendingIntent.getActivity(this, 0 /* Request code */, intentLieu,
            PendingIntent.FLAG_ONE_SHOT);

    /*  Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
      NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.profile_seb)
        .setContentTitle("GCM Message")
        .setContentText(message)
        .setAutoCancel(true)
        .setSound(defaultSoundUri)
        .setContentIntent(pendingIntent);*/

    // Constructs the Builder object.

    Intent lieuIntent = new Intent(this, LieuActivity.class);

    Notification n = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.icon).setContentTitle(title)
            .setContentText(message).setDefaults(Notification.DEFAULT_ALL) // requires VIBRATE permission
            .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
            .addAction(R.drawable.cast_ic_notification_0, "Ignorer", pendingIntentHome)
            .addAction(R.drawable.cast_ic_notification_on, "Y aller", pendingIntentLieu).build();

    n.sound = Uri.parse("android.resource://" + this.getPackageName() + "/" + R.raw.sif);

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    notificationManager.notify(0, n);

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

    //  notificationManager.notify(0 /* ID of notification */,notificationBuilder.build());
}

From source file:net.nym.napply.library.utils.Notify.java

/**
 * Displays a notification in the notification area of the UI
 * @param context Context from which to create the notification
 * @param messageString The string to display to the user as a message
 * @param smallIconId drawable id//from w  ww  .  j  a  v  a2  s.  co m
 * @param intent The intent which will start the activity when the user clicks the notification
 * @param notificationTitle The resource reference to the notification title
 * @return messageID
 */
public static int notifcation(Context context, String messageString, int smallIconId, Intent intent,
        String notificationTitle) {

    //Get the notification manage which we will use to display the notification
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);

    Calendar.getInstance().getTime().toString();

    long when = System.currentTimeMillis();

    //get the notification title from the application's strings.xml file
    CharSequence contentTitle = notificationTitle;

    //the message that will be displayed as the ticker
    String ticker = contentTitle + " " + messageString;

    //build the pending intent that will start the appropriate activity
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 3, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    //build the notification
    Builder notificationCompat = new Builder(context);
    notificationCompat.setAutoCancel(true).setContentTitle(contentTitle).setContentIntent(pendingIntent)
            .setContentText(messageString).setTicker(ticker).setWhen(when).setSmallIcon(smallIconId)

    ;

    Notification notification = notificationCompat.build();
    //    notification.defaults |= Notification.DEFAULT_ALL;
    notification.defaults = Notification.DEFAULT_ALL;
    //display the notification
    mNotificationManager.notify(MessageID, notification);
    return MessageID++;

}

From source file:can.yrt.onebusaway.tripservice.NotifierTask.java

private Notification createNotification(Uri alertUri) {
    //Log.d(TAG, "Creating notification for alert: " + alertUri);
    Intent deleteIntent = new Intent(mContext, TripService.class);
    deleteIntent.setAction(TripService.ACTION_CANCEL);
    deleteIntent.setData(alertUri);//  w ww.j  a v a2s . c  o  m

    return new NotificationCompat.Builder(mContext).setSmallIcon(R.drawable.ic_stat_notification)
            .setDefaults(Notification.DEFAULT_ALL).setOnlyAlertOnce(true)
            //.setLights(0xFF00FF00, 1000, 1000)
            //.setVibrate(VIBRATE_PATTERN)
            .setDeleteIntent(
                    PendingIntent.getService(mContext, 0, deleteIntent, PendingIntent.FLAG_UPDATE_CURRENT))
            .getNotification();
}

From source file:org.c99.wear_imessage.GCMIntentService.java

public static void notify(Context context, int notification_id, JSONArray msgs, Intent intent,
        boolean updateOnly) throws JSONException {
    String lastMsg = intent.getStringExtra("msg");
    Spanned msg;/*from w w  w .  j  av  a  2  s .c o  m*/
    String name = intent.getStringExtra("name");
    if (name.contains(" "))
        name = name.substring(0, name.indexOf(" "));

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < msgs.length(); i++) {
        if (sb.length() > 0)
            sb.append("<br/><br/>");
        String body;
        String from = name;

        try {
            JSONObject o = msgs.getJSONObject(i);
            body = o.getString("msg");
            if (o.has("type")) {
                if (o.getString("type").equals("file") || o.getString("type").equals("sent_file"))
                    body = "[File: " + o.getString("msg") + "]";

                if (o.getString("type").equals("sent") || o.getString("type").equals("sent_file"))
                    from = "Me";
                else
                    lastMsg = body;
            } else {
                from = name;
                lastMsg = body;
            }
        } catch (JSONException e1) {
            from = name;
            body = msgs.getString(i);
            lastMsg = body;
        }

        sb.append("<b>").append(Html.escapeHtml(from)).append(":</b> ").append(Html.escapeHtml(body));
    }

    msg = Html.fromHtml(sb.toString());
    int msg_count = msgs.length();

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

    if (name.length() > 0) {
        builder.setSmallIcon(R.drawable.ic_notification).setContentTitle(intent.getStringExtra("name"))
                .setContentText(lastMsg).setNumber(msg_count);
    }

    if (updateOnly) {
        builder.setVibrate(null);
    } else {
        builder.setPriority(NotificationCompat.PRIORITY_HIGH);
        builder.setTicker(Html.fromHtml("<b>" + Html.escapeHtml(intent.getStringExtra("name")) + ":</b> "
                + Html.escapeHtml(intent.getStringExtra("msg")))).setDefaults(Notification.DEFAULT_ALL);
    }

    NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle();
    style.bigText(lastMsg);
    builder.setStyle(style);

    NotificationCompat.WearableExtender extender = new NotificationCompat.WearableExtender();

    if (ENABLE_REPLIES) {
        Intent replyIntent = new Intent(RemoteInputService.ACTION_REPLY);
        replyIntent
                .setComponent(new ComponentName(context.getPackageName(), RemoteInputService.class.getName()));
        replyIntent.putExtras(intent.getExtras());
        replyIntent.putExtra("notification_id", notification_id);
        PendingIntent replyPendingIntent = PendingIntent.getService(context, notification_id + 1, replyIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);
        extender.addAction(
                new NotificationCompat.Action.Builder(R.drawable.ic_reply, "Reply", replyPendingIntent)
                        .addRemoteInput(new RemoteInput.Builder("extra_reply").setLabel("Reply").build())
                        .build());

        Intent launchIntent = new Intent(context, QuickReplyActivity.class);
        launchIntent.putExtras(intent.getExtras());
        launchIntent.putExtra("notification_id", notification_id);
        builder.setContentIntent(PendingIntent.getActivity(context, notification_id + 2, launchIntent,
                PendingIntent.FLAG_CANCEL_CURRENT));
        builder.addAction(R.drawable.ic_action_reply, "Reply",
                PendingIntent.getActivity(context, notification_id + 3, launchIntent,
                        PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT));
    }

    if (msg_count > 1)
        extender.addPage(new NotificationCompat.Builder(context).setContentText(msg)
                .extend(new NotificationCompat.WearableExtender().setStartScrollBottom(true)).build());

    Cursor c = null;
    if (intent.getStringExtra("handle").contains("@"))
        c = context.getContentResolver().query(ContactsContract.Data.CONTENT_URI,
                new String[] { ContactsContract.Data.CONTACT_ID },
                ContactsContract.CommonDataKinds.Email.ADDRESS + "=?" + " AND " + ContactsContract.Data.MIMETYPE
                        + "=?",
                new String[] { intent.getStringExtra("handle"),
                        ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE },
                null);

    if (c != null && c.moveToFirst()) {
        long contactId = c.getLong(0);
        c.close();

        Bitmap b = BitmapFactory.decodeStream(
                ContactsContract.Contacts.openContactPhotoInputStream(context.getContentResolver(),
                        ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId), true));
        if (b != null) {
            builder.setLargeIcon(b);
            extender.setBackground(b);
        }
    }

    NotificationManagerCompat m = NotificationManagerCompat.from(context);
    m.notify(notification_id, builder.extend(extender).build());
}

From source file:org.fdroid.fdroid.installer.InstallIntoSystemDialogActivity.java

public static void runFirstTime(final Context context) {
    // don't do a "real" root access, just look up if "su" is present and has a version!
    // a real check would annoy the user
    AsyncTask<Void, Void, Boolean> checkRoot = new AsyncTask<Void, Void, Boolean>() {

        @Override//from w  w w  .  ja  v  a  2  s  . c om
        protected Boolean doInBackground(Void... params) {
            return (Shell.SU.version(true) != null);
        }

        @Override
        protected void onPostExecute(Boolean probablyRoot) {
            super.onPostExecute(probablyRoot);

            if (probablyRoot) {
                // looks like we have root, at least su has a version number and is present

                Intent installIntent = new Intent(context, InstallIntoSystemDialogActivity.class);
                installIntent.setAction(InstallIntoSystemDialogActivity.ACTION_FIRST_TIME);
                installIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, installIntent,
                        PendingIntent.FLAG_UPDATE_CURRENT);

                NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
                        .setContentIntent(resultPendingIntent).setSmallIcon(R.drawable.ic_stat_notify)
                        .setContentTitle(context.getString(R.string.system_install_first_time_notification))
                        .setContentText(context
                                .getString(R.string.system_install_first_time_notification_message_short))
                        .setDefaults(Notification.DEFAULT_ALL).setAutoCancel(true)
                        /*
                         * Sets the big view "big text" style and supplies the
                         * text (the user's reminder message) that will be displayed
                         * in the detail area of the expanded notification.
                         * These calls are ignored by the support library for
                         * pre-4.1 devices.
                         */
                        .setStyle(new NotificationCompat.BigTextStyle().bigText(
                                context.getString(R.string.system_install_first_time_notification_message)));

                NotificationManager nm = (NotificationManager) context
                        .getSystemService(Context.NOTIFICATION_SERVICE);
                nm.notify(42, builder.build());
            }
        }
    };
    checkRoot.execute();
}