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.hybris.mobile.lib.location.geofencing.service.GeofencingIntentService.java

/**
 * Send a notification when a geofence is triggered
 *
 * @param geofence           the geofence triggered
 * @param notification       the notification object
 * @param geofenceTransition the geofence transition type
 *//*w w  w. ja v a2s. com*/
protected void sendNotification(Geofence geofence, GeofenceObject.Notification notification,
        int geofenceTransition) {

    if (notification != null) {

        // Notification
        String notificationContentTitle = notification.getNotificationTitle();
        String notificationContentText = notification.getNotificationText();
        int notificationIconResId = notification.getNotificationIconResId();

        Notification.Builder builder = new Notification.Builder(this);

        builder.setContentTitle(notificationContentTitle).setContentText(notificationContentText);

        if (notificationIconResId > 0) {
            builder.setSmallIcon(notificationIconResId);
        }

        try {
            // Intent on click on the notification
            if (StringUtils.isNotBlank(notification.getIntentClassDestination())) {
                Class<?> intentClassDestination = Class.forName(notification.getIntentClassDestination());

                // Create an explicit content Intent that starts the Activity defined in intentClassDestination
                Intent notificationIntent = new Intent(this, intentClassDestination);

                // Geofence Id to pass to the activity in order to retrieve the object
                if (notification.getIntentBundle() != null) {
                    GeofenceObject.IntentBundle intentBundle = notification.getIntentBundle();
                    notificationIntent.putExtra(intentBundle.getKeyName(), intentBundle.getBundle());

                    // Easter egg :)
                    if (intentBundle.getBundle().getBoolean(GeofencingConstants.EXTRA_PLAY_SOUND)) {
                        MediaPlayer mediaPlayer;
                        if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER) {
                            Log.d(TAG, "Playing entering geofence sound");
                            mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.entering_geofence);
                        } else {
                            Log.d(TAG, "Playing exiting geofence sound");
                            mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.leaving_geofence);
                        }

                        mediaPlayer.start();
                    }
                }

                PendingIntent notificationPendingIntent = PendingIntent.getActivity(this,
                        geofence.getRequestId().hashCode(), notificationIntent,
                        PendingIntent.FLAG_UPDATE_CURRENT);

                builder.setContentIntent(notificationPendingIntent);
            }

        } catch (ClassNotFoundException e) {
            Log.e(TAG, "Unable to find class " + notification.getIntentClassDestination() + "."
                    + e.getLocalizedMessage());
        }

        // Constructing the Notification and setting the flag to auto remove the notification when the user click on it
        Notification notificationView;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            notificationView = builder.build();
        } else {
            notificationView = builder.getNotification();
        }

        notificationView.flags = Notification.FLAG_AUTO_CANCEL;
        notificationView.defaults = Notification.DEFAULT_ALL;

        // Get an instance of the Notification manager
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);

        // Issue the notification
        mNotificationManager.notify(UUID.randomUUID().toString().hashCode(), notificationView);
    } else {
        Log.e(TAG, "Notification empty for Geofence " + geofence);
    }

}

From source file:com.ayogo.cordova.notification.ScheduledNotificationManager.java

public void showNotification(ScheduledNotification scheduledNotification) {
    LOG.v(NotificationPlugin.TAG, "showNotification: " + scheduledNotification.toString());

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

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

    // Build the notification options
    builder.setDefaults(Notification.DEFAULT_ALL).setTicker(scheduledNotification.body)
            .setPriority(Notification.PRIORITY_HIGH).setAutoCancel(true);

    // TODO: add sound support
    // if (scheduledNotification.sound != null) {
    //     builder.setSound(sound);
    // }/* w  w  w  .j ava2s . co  m*/

    if (scheduledNotification.body != null) {
        builder.setContentTitle(scheduledNotification.title);
        builder.setContentText(scheduledNotification.body);
        builder.setStyle(new NotificationCompat.BigTextStyle().bigText(scheduledNotification.body));
    } else {
        //Default the title to the app name
        try {
            PackageManager pm = context.getPackageManager();
            ApplicationInfo applicationInfo = pm.getApplicationInfo(context.getPackageName(),
                    PackageManager.GET_META_DATA);

            String appName = applicationInfo.loadLabel(pm).toString();

            builder.setContentTitle(appName);
            builder.setContentText(scheduledNotification.title);
            builder.setStyle(new NotificationCompat.BigTextStyle().bigText(scheduledNotification.title));
        } catch (NameNotFoundException e) {
            LOG.v(NotificationPlugin.TAG, "Failed to set title for notification!");
            return;
        }
    }

    if (scheduledNotification.badge != null) {
        LOG.v(NotificationPlugin.TAG, "showNotification: has a badge!");
        builder.setSmallIcon(getResIdForDrawable(scheduledNotification.badge));
    } else {
        LOG.v(NotificationPlugin.TAG, "showNotification: has no badge, use app icon!");
        try {
            PackageManager pm = context.getPackageManager();
            ApplicationInfo applicationInfo = pm.getApplicationInfo(context.getPackageName(),
                    PackageManager.GET_META_DATA);
            Resources resources = pm.getResourcesForApplication(applicationInfo);
            builder.setSmallIcon(applicationInfo.icon);
        } catch (NameNotFoundException e) {
            LOG.v(NotificationPlugin.TAG, "Failed to set badge for notification!");
            return;
        }
    }

    if (scheduledNotification.icon != null) {
        LOG.v(NotificationPlugin.TAG, "showNotification: has an icon!");
        builder.setLargeIcon(getIconFromUri(scheduledNotification.icon));
    } else {
        LOG.v(NotificationPlugin.TAG, "showNotification: has no icon, use app icon!");
        try {
            PackageManager pm = context.getPackageManager();
            ApplicationInfo applicationInfo = pm.getApplicationInfo(context.getPackageName(),
                    PackageManager.GET_META_DATA);
            Resources resources = pm.getResourcesForApplication(applicationInfo);
            Bitmap appIconBitmap = BitmapFactory.decodeResource(resources, applicationInfo.icon);
            builder.setLargeIcon(appIconBitmap);
        } catch (NameNotFoundException e) {
            LOG.v(NotificationPlugin.TAG, "Failed to set icon for notification!");
            return;
        }
    }

    Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
    launchIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    launchIntent.setAction("notification");

    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launchIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(contentIntent);

    Notification notification = builder.build();

    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    LOG.v(NotificationPlugin.TAG, "notify!");
    notificationManager.notify(scheduledNotification.tag.hashCode(), notification);
}

From source file:ru.orangesoftware.financisto.service.FinancistoService.java

private Notification createRestoredNotification(int count) {
    long when = System.currentTimeMillis();
    String text = getString(R.string.scheduled_transactions_have_been_restored, count);

    NotificationCompat.Builder b = new NotificationCompat.Builder(this);
    b.setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL);
    b.setSmallIcon(R.drawable.notification_icon_transaction);
    b.setContentText(text);//  ww  w .  ja v a2 s .  co m
    b.setWhen(when);

    Intent notificationIntent = new Intent(this, MassOpActivity.class);
    WhereFilter filter = new WhereFilter("");
    filter.eq(BlotterFilter.STATUS, TransactionStatus.RS.name());
    filter.toIntent(notificationIntent);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    b.setContentIntent(contentIntent);

    return b.build();
}

From source file:com.tcs.geofenceplugin.GeofenceTransitionsIntentService.java

private void sendNotification(String notificationDetails, String contenttext, String place) {
    Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(notificationIntent);
    PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0,
            PendingIntent.FLAG_UPDATE_CURRENT);

    notificationDetails = notificationDetails.substring(0, notificationDetails.length() - 1);

    Notification n = new Notification.Builder(this).setContentTitle("Entered :" + place)
            .setContentText(contenttext).setSmallIcon(R.drawable.ic_launcher)
            .setContentIntent(notificationPendingIntent).setAutoCancel(true)
            .setDefaults(Notification.DEFAULT_ALL).build();

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(0, n);/*from   w w w  . j  a  v a 2  s .  com*/

}

From source file:eu.nerdz.app.messenger.GcmIntentService.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private synchronized void notifyUser(String from, int fromId, String message) {

    from = Html.fromHtml(from).toString();
    message = Html.fromHtml(message).toString();

    if (this.isActivityOpen()) {
        Log.d(TAG, "Activity is open");

        Message message1 = this.makeMessage(from, fromId, message);

        Intent intent = new Intent(GcmIntentService.MESSAGE_EVENT);
        intent.putExtra(GcmIntentService.MESSAGE_EVENT, message1);

        this.mLocalBroadcastManager.sendBroadcast(intent);

        return;//from  w w w.ja va2  s  .c  om
    }

    message = GcmIntentService.ellipsize(message, 60);

    String ticker = from + ": " + message;

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

    int counter = MessagesHolder.append(from, message);

    Log.d(TAG, "" + counter);

    PendingIntent openIntent = null;

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    if (counter > 1) {

        NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();

        from = String.format(this.getString(R.string.notify_new_messages), counter);
        message = this.getString(R.string.notify_swipe);

        style.setBigContentTitle(from);
        style.setSummaryText(Server.getInstance().getName());

        for (Pair<String, String> pair : MessagesHolder.get()) {
            style.addLine(
                    Html.fromHtml("<b>" + GcmIntentService.ellipsize(pair.first, 20) + "</b> " + pair.second));
        }

        builder.setStyle(style);

        stackBuilder.addParentStack(ConversationsListActivity.class);
        stackBuilder.addNextIntent(new Intent(this, ConversationsListActivity.class));
        openIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    } else {

        stackBuilder.addParentStack(ConversationActivity.class);

        Intent intent = new Intent(this, ConversationActivity.class);

        intent.putExtra(Keys.FROM, from);
        intent.putExtra(Keys.FROM_ID, fromId);

        stackBuilder.addNextIntent(intent);
        openIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    }

    builder //Sorry Robertof, no enormous oneliners today
            .setSmallIcon(R.drawable.ic_stat).setContentTitle(from).setContentText(message)
            .setContentIntent(openIntent).setDefaults(Notification.DEFAULT_ALL).setNumber(counter)
            .setTicker(ticker);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        builder.setPriority(Notification.PRIORITY_HIGH);
    }

    this.mNotificationManager.notify(MSG_ID, builder.build());

}

From source file:com.geomoby.geodeals.DemoService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *//*from   w w  w  .  ja va2s  . com*/
private static void generateNotification(Context context, String message) {
    if (message.length() > 0) {

        // Parse the GeoMoby message using the GeoMessage class
        try {
            Gson gson = new Gson();
            JsonParser parser = new JsonParser();
            JsonArray Jarray = parser.parse(message).getAsJsonArray();
            ArrayList<GeoMessage> alerts = new ArrayList<GeoMessage>();
            for (JsonElement obj : Jarray) {
                GeoMessage gName = gson.fromJson(obj, GeoMessage.class);
                alerts.add(gName);
            }

            // Prepare Notification and pass the GeoMessage to an Extra
            NotificationManager notificationManager = (NotificationManager) context
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            Intent i = new Intent(context, CustomNotification.class);
            i.putParcelableArrayListExtra("GeoMessage", (ArrayList<GeoMessage>) alerts);
            PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, i,
                    PendingIntent.FLAG_UPDATE_CURRENT);

            // Read from the /assets directory
            Resources resources = context.getResources();
            AssetManager assetManager = resources.getAssets();
            try {
                InputStream inputStream = assetManager.open("geomoby.properties");
                Properties properties = new Properties();
                properties.load(inputStream);
                String push_icon = properties.getProperty("push_icon");
                int icon = resources.getIdentifier(push_icon, "drawable", context.getPackageName());
                int not_title = resources.getIdentifier("notification_title", "string",
                        context.getPackageName());
                int not_text = resources.getIdentifier("notification_text", "string", context.getPackageName());
                int not_ticker = resources.getIdentifier("notification_ticker", "string",
                        context.getPackageName());

                // Manage notifications differently according to Android version
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);

                    builder.setSmallIcon(icon).setContentTitle(context.getResources().getText(not_title))
                            .setContentText(context.getResources().getText(not_text))
                            .setTicker(context.getResources().getText(not_ticker))
                            .setContentIntent(pendingIntent).setAutoCancel(true);

                    builder.setDefaults(Notification.DEFAULT_ALL); //Vibrate, Sound and Led

                    // Because the ID remains unchanged, the existing notification is updated.
                    notificationManager.notify(notifyID, builder.build());

                } else {
                    Notification notification = new Notification(icon, context.getResources().getText(not_text),
                            System.currentTimeMillis());

                    //Setting Notification Flags
                    notification.defaults |= Notification.DEFAULT_ALL;
                    notification.flags |= Notification.FLAG_AUTO_CANCEL;

                    //Set the Notification Info
                    notification.setLatestEventInfo(context, context.getResources().getText(not_text),
                            context.getResources().getText(not_ticker), pendingIntent);

                    //Send the notification
                    // Because the ID remains unchanged, the existing notification is updated.
                    notificationManager.notify(notifyID, notification);
                }
            } catch (IOException e) {
                System.err.println("Failed to open geomoby property file");
                e.printStackTrace();
            }
        } catch (JsonParseException e) {
            Log.i(TAG, "This is not a GeoMoby notification");
            throw new RuntimeException(e);
        }
    }
}

From source file:com.ingeneo.cordova.plugins.ibeacon.GPIBeacon.java

/**
 * + * Issues a notification to inform the user that server has sent a
 * message. +/*from  w w w.  j a  v a2 s.  co m*/
 * 
 * @throws JSONException
 */
private static void createNotification(Context context, JSONObject json) throws JSONException {
    Bundle extra = new Bundle();
    extra.putString("json", json.toString());

    Intent notificationIntent = new Intent(activity, BeaconNotificationHandler.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.putExtra("beacon", extra);

    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    JSONObject obj = json.getJSONObject("ibeacon");
    String message = obj.getString("message");
    String title = obj.getString("title");
    if (title == null || title == "") {
        title = context.getApplicationInfo().name;
    }

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setDefaults(Notification.DEFAULT_ALL).setWhen(System.currentTimeMillis()).setTicker(message)
            .setContentTitle(title).setContentText(message).setSmallIcon(context.getApplicationInfo().icon)
            .setContentIntent(contentIntent);

    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();

    // Sets a title for the Inbox style big view
    inboxStyle.setBigContentTitle("Beacons");

    // Moves events into the big view
    for (int i = 0; i < itemsNotification.size(); i++) {
        JSONObject beacon = beaconsData.get(itemsNotification.get(i));
        inboxStyle.addLine(beacon.getString("message"));
    }
    // Moves the big view style object into the notification object.
    mBuilder.setStyle(inboxStyle);

    if (message != null) {
        mBuilder.setContentText(message);
    } else {
        mBuilder.setContentText("<missing message content>");
    }
    mBuilder.addAction(context.getApplicationInfo().icon, "Ver mas", contentIntent);

    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE))
            .notify((String) getAppName(context), NOTIFICATION_ID, mBuilder.build());

}

From source file:com.medlog.medlogmobile.NewMessageNotification.java

public static void notify(final Context context, final String exampleString[], final int number) {
    final Resources res = context.getResources();

    // This image is used as the notification's large icon (thumbnail).
    // TODO: Remove this if your notification has no relevant thumbnail.
    final Bitmap picture = BitmapFactory.decodeResource(res, R.drawable.ml);

    final int stringLen = exampleString.length;
    if (stringLen != 4) {

    }/*  w  w w . j a  va  2s.c om*/
    final String userName = exampleString[0];
    final String entries = exampleString[1];
    final String entryTitle = exampleString[2];
    final String entryBody = exampleString[3];
    final String date = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date());
    final String sync = "";
    final String title = res.getString(R.string.new_message_notification_title_template, entryTitle);
    final String text = res.getString(R.string.new_message_notification_placeholder_text_template, date,
            userName, entries);

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

            // Set appropriate defaults for the notification light, sound,
            // and vibration.
            .setDefaults(Notification.DEFAULT_ALL)

            // Set required fields, including the small icon, the
            // notification title, and text.
            .setSmallIcon(R.drawable.notification_template_icon_bg)//.ic_stat_new_message)
            .setContentTitle(title).setContentText(text)

            // All fields below this line are optional.

            // Use a default priority (recognized on devices running Android
            // 4.1 or later)
            .setPriority(NotificationCompat.PRIORITY_DEFAULT)

            // Provide a large icon, shown with the notification in the
            // notification drawer on devices running Android 3.0 or later.
            .setLargeIcon(picture)

            // Set ticker text (preview) information for this notification.
            .setTicker(title)

            // Show a number. This is useful when stacking notifications of
            // a single type.
            .setNumber(number)

            // If this notification relates to a past or upcoming event, you
            // should set the relevant time information using the setWhen
            // method below. If this call is omitted, the notification's
            // timestamp will by set to the time at which it was shown.
            // TODO: Call setWhen if this notification relates to a past or
            // upcoming event. The sole argument to this method should be
            // the notification timestamp in milliseconds.
            //.setWhen(...)

            // Set the pending intent to be initiated when the user touches
            // the notification.
            .setContentIntent(PendingIntent.getActivity(context, 0,
                    new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.niftybull.com/MedLogRS")),
                    PendingIntent.FLAG_UPDATE_CURRENT))

            // Show expanded text content on devices running Android 4.1 or
            // later.
            .setStyle(new NotificationCompat.BigTextStyle().bigText(text).setBigContentTitle(title)
                    .setSummaryText(entryTitle))

            // Example additional actions for this notification. These will
            // only show on devices running Android 4.1 or later, so you
            // should ensure that the activity in this notification's
            // content intent provides access to the same actions in
            // another way.
            .addAction(R.drawable.ic_action_stat_share, res.getString(R.string.action_share),
                    PendingIntent.getActivity(context, 0,
                            Intent.createChooser(
                                    new Intent(Intent.ACTION_SEND).setType("text/plain")
                                            .putExtra(Intent.EXTRA_SUBJECT, title)
                                            .putExtra(Intent.EXTRA_TEXT, date + " : " + entryBody),
                                    context.getString(R.string.msg_jrv)),
                            PendingIntent.FLAG_UPDATE_CURRENT))
            .addAction(R.drawable.ic_action_stat_reply, res.getString(R.string.action_reply), null)

            // Automatically dismiss the notification when it is touched.
            .setAutoCancel(true);

    notify(context, builder.build());
}

From source file:ru.orangesoftware.financisto.service.FinancistoService.java

private Notification createNotification(TransactionInfo t) {
    long when = System.currentTimeMillis();

    NotificationCompat.Builder b = new NotificationCompat.Builder(this);
    b.setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL);
    b.setSmallIcon(t.getNotificationIcon());
    b.setContentText(t.getNotificationTickerText(this));
    b.setWhen(when);/*from w  w w  .  ja v a 2 s.  c o  m*/

    Intent notificationIntent = new Intent(this, t.getActivity());
    notificationIntent.putExtra(AbstractTransactionActivity.TRAN_ID_EXTRA, t.id);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    b.setContentTitle(t.getNotificationContentTitle(this));
    b.setContentIntent(contentIntent);

    Notification notification = b.build();

    applyNotificationOptions(notification, t.notificationOptions);

    return notification;
}

From source file:ufms.br.com.ufmsapp.gcm.UfmsGcmListenerService.java

private void buildGcmNotification(String title, String msg, Class mClass, String intentExtraName,
        String valueId) {//  w w w.j  a va  2  s.  co  m
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    boolean isSoundEnabled = prefs.getBoolean(getResources().getString(R.string.pref_notification_sound), true);

    NotificationManagerCompat nm = NotificationManagerCompat.from(this);
    Intent it = new Intent(this, mClass);
    it.putExtra(intentExtraName, valueId);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addNextIntent(it);
    PendingIntent pit = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);

    if (isSoundEnabled) {
        mBuilder.setDefaults(Notification.DEFAULT_ALL);
    }

    NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle();
    bigTextStyle.setBigContentTitle(title).bigText(msg);

    mBuilder.setStyle(bigTextStyle);
    mBuilder.setAutoCancel(true);
    mBuilder.setContentIntent(pit);
    mBuilder.setColor(ContextCompat.getColor(this, R.color.accentColor));
    mBuilder.setSmallIcon(R.mipmap.ic_launcher_white);
    mBuilder.setContentTitle(title);
    mBuilder.setContentText(msg);
    nm.notify(NOTIFICATION_ID, mBuilder.build());
}