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.vinexs.eeb.receiver.BaseReceiverGCM.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
public void onMessageTypeReceive(Context context, Intent intent) {
    notifyMgr = NotificationManagerCompat.from(context);
    SharedPreferences setting = PreferenceManager.getDefaultSharedPreferences(context);
    int notifyId = setting.getInt("notifyId", new Random().nextInt(65535));
    Bundle receIntent = intent.getExtras();
    try {//from   w  w  w  .j a v a 2  s  .c  om
        if (!receIntent.containsKey("contentTitle") || !receIntent.containsKey("contentText")) {
            throw new Exception("Message don't contain necessary data.");
        }

        if (builder == null) {
            builder = new NotificationCompat.Builder(context);
            contentTitle = receIntent.getCharSequence("contentTitle");
            contentText = receIntent.getCharSequence("contentText");

            builder.setDefaults(Notification.DEFAULT_ALL).setContentTitle(contentTitle)
                    .setContentText(contentText).setSmallIcon(getMonoColorIcon())
                    .setWhen(System.currentTimeMillis()).setAutoCancel(true).setOnlyAlertOnce(true);
            try {
                if (Build.VERSION.SDK_INT < 14 || !receIntent.containsKey("largeIcon")) {
                    throw new Exception("Message don't contain [largeIcon] or device SDK lower than 14.");
                }
                String bigIconUrl = receIntent.getString("largeIcon");
                if (bigIconUrl == null || bigIconUrl.isEmpty()) {
                    throw new Exception("Message [largeIcon] is empty.");
                }
                HttpURLConnection connection = (HttpURLConnection) new URL(bigIconUrl).openConnection();
                connection.setDoInput(true);
                connection.connect();
                Bitmap bigIcon = BitmapFactory.decodeStream(connection.getInputStream());
                builder.setLargeIcon(bigIcon);
                // Add backgroud to wearable
                NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender();
                wearableExtender.setBackground(bigIcon);
                builder.extend(wearableExtender);
                // Set accent color
                int[] attrs = new int[] { R.attr.colorAccent };
                TypedArray ta = context.obtainStyledAttributes(attrs);
                String colorAccent = ta.getString(0);
                ta.recycle();
                builder.setColor(Color.parseColor(colorAccent));
            } catch (Exception e) {
                builder.setLargeIcon(
                        BitmapFactory.decodeResource(context.getResources(), getApplicationIcon()));
            }
            try {
                if (!receIntent.containsKey("ticker")) {
                    throw new Exception("Message don't contain [ticker].");
                }
                builder.setTicker(receIntent.getCharSequence("ticker"));
            } catch (Exception e) {
                builder.setTicker(receIntent.getCharSequence("contentText"));
            }
            if (Build.VERSION.SDK_INT >= 16) {
                builder.setStyle(new NotificationCompat.BigTextStyle().bigText(contentText));
            }
        } else {
            contentText = contentText + "\n" + receIntent.getCharSequence("contentText");
            messageNum++;
            builder.setContentTitle(Utility.getAppName(context)).setContentText(contentText)
                    .setTicker(receIntent.getCharSequence("contentText")).setNumber(messageNum);
        }

        if (Build.VERSION.SDK_INT >= 16) {
            builder.setStyle(new NotificationCompat.BigTextStyle().bigText(contentText));
        }

        Intent actionIntent = new Intent(context, getLauncherClass());
        if (receIntent.containsKey("intentAction")) {
            actionIntent.putExtra("onNewIntentAction", receIntent.getCharSequence("intentAction"));
        }
        actionIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP
                | Intent.FLAG_INCLUDE_STOPPED_PACKAGES);

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

        notifyMgr.notify(notifyId, builder.build());
    } catch (Exception e) {
        Log.d("GoogleCloudMessaging",
                "Exception occurred while show message as notification -> " + e.toString());
        e.printStackTrace();
    }
}

From source file:com.commonsware.android.andshooter.ScreenshotService.java

private void foregroundify() {
    NotificationCompat.Builder b = new NotificationCompat.Builder(this);

    b.setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL);

    b.setContentTitle(getString(R.string.app_name)).setSmallIcon(R.mipmap.ic_launcher)
            .setTicker(getString(R.string.app_name));

    b.addAction(R.drawable.ic_record_white_24dp, getString(R.string.notify_record),
            buildPendingIntent(ACTION_RECORD));

    b.addAction(R.drawable.ic_eject_white_24dp, getString(R.string.notify_shutdown),
            buildPendingIntent(ACTION_SHUTDOWN));

    startForeground(NOTIFY_ID, b.build());
}

From source file:com.kratav.tinySurprise.notification.MyGcmListenerService.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private Notification notificationType2() {
    Bitmap smallIconBitmap = getMeBitmap(smallIcon);
    if (smallIconBitmap == null)
        return null;

    // Constructs the Builder object.
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setContentTitle(title)
            .setTicker(title).setSubText(subtitle).setSmallIcon(R.drawable.ic_launcher)
            .setLargeIcon(smallIconBitmap).setDefaults(Notification.DEFAULT_ALL) // requires VIBRATE permission
            .setStyle(new NotificationCompat.BigTextStyle().bigText(bigMsg))
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    builder.setContentIntent(pendingIntent);
    return builder.build();
}

From source file:com.z3r0byte.magistify.Services.NewGradeService.java

private void GradeChecker() {
    TimerTask refreshSession = new TimerTask() {
        @Override// w ww  .  j a v  a 2 s.  c  o  m
        public void run() {
            Magister magister = GlobalAccount.MAGISTER;
            if (magister == null || magister.isExpired()) {
                Log.e(TAG, "run: Invalid magister");
                return;
            }

            NewGradesDB gradesdb = new NewGradesDB(getApplicationContext());

            GradeHandler gradeHandler = new GradeHandler(magister);
            Grade[] gradeArray;
            List<Grade> gradeList = new ArrayList<Grade>();
            try {
                gradeArray = gradeHandler.getRecentGrades();
                gradesdb.addGrades(gradeArray);
                Collections.reverse(Arrays.asList(gradeArray));

                //For testing purposes:
                /*Grade sampleGrade = new Grade();
                sampleGrade.isSufficient = false;
                sampleGrade.grade = "2.3";
                sampleGrade.subject = new SubSubject();
                sampleGrade.subject.name = "Latijn";
                        
                Grade sampleGrade2 = new Grade();
                sampleGrade2.isSufficient = true;
                sampleGrade2.grade = "6.5";
                sampleGrade2.subject = new SubSubject();
                sampleGrade2.subject.name = "Nederlands";
                        
                gradeArray = new Grade[2];
                gradeArray[0] = sampleGrade;
                gradeArray[1] = sampleGrade2;*/

                for (Grade grade : gradeArray) {
                    if (!gradesdb.hasBeenSeen(grade, false)
                            && (grade.isSufficient || !configUtil.getBoolean("pass_grades_only"))) {
                        gradeList.add(grade);
                    }
                }

            } catch (IOException e) {
                e.printStackTrace();
                return;
            }
            String GradesNotification = new Gson().toJson(gradeList);
            if (gradeList != null && gradeList.size() > 0
                    && !configUtil.getString("lastGradesNotification").equals(GradesNotification)) {

                Log.d(TAG, "run: Some grades to show: " + gradeList.size());

                NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext());
                mBuilder.setSmallIcon(R.drawable.ic_grade_notification);

                if (gradeList.size() == 1) {
                    Grade grade = gradeList.get(0);
                    mBuilder.setContentTitle("Nieuw cijfer voor " + grade.subject.name);
                    //mBuilder.setStyle(new NotificationCompat.BigTextStyle(mBuilder).bigText())
                    mBuilder.setContentText("Een " + grade.grade);
                } else {
                    String content = "";
                    for (Grade grade : gradeList) {
                        String string = grade.subject.name + ", een " + grade.grade;
                        if (content.length() > 1) {
                            content = content + "\n" + string;
                        } else {
                            content = string;
                        }
                    }
                    mBuilder.setContentTitle("Nieuwe cijfers voor:");
                    mBuilder.setStyle(new NotificationCompat.BigTextStyle(mBuilder).bigText(content));
                    mBuilder.setContentText(content);
                }
                mBuilder.setAutoCancel(true);
                mBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
                mBuilder.setDefaults(Notification.DEFAULT_ALL);

                Intent resultIntent = new Intent(getApplicationContext(), NewGradeActivity.class);
                TaskStackBuilder stackBuilder = TaskStackBuilder.create(getApplicationContext());
                stackBuilder.addParentStack(NewGradeActivity.class);
                stackBuilder.addNextIntent(resultIntent);
                PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
                        PendingIntent.FLAG_UPDATE_CURRENT);
                mBuilder.setContentIntent(resultPendingIntent);

                NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                        Context.NOTIFICATION_SERVICE);
                mNotificationManager.notify(9992, mBuilder.build());

                configUtil.setString("lastGradesNotification", GradesNotification);
            } else {
                Log.w(TAG, "run: No grades!");
            }
        }
    };
    timer.schedule(refreshSession, 6000, 10 * 1000);
}

From source file:org.ohmage.reminders.notif.Notifier.java

private static void displayNotification(Context context, ArrayList<String> surveys, boolean quiet) {

    // If the notification is to be refreshed quietly, and if it is hidden, do nothing.
    if (quiet && !getNotifVisibility(context)) {
        return;/* w w  w  .  j a va2s. c  om*/
    }

    // Cancel any alarms to reshow the notification because we are showing it now
    cancelAlarm(context, ACTION_NOTIF_RESHOW);

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

    //Watch for notification cleared events
    Intent deleteIntent = new Intent(context, NotifReceiver.class).setAction(ACTION_NOTIF_DELETED);
    PendingIntent piDelete = PendingIntent.getBroadcast(context, 0, deleteIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    //Watch for notification clicked events
    Intent intent = new Intent(context, NotifReceiver.class).setAction(ACTION_NOTIF_CLICKED)
            .putExtra(EXTRA_SURVEYS, new ArrayList<String>(surveys));
    PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

    // Constructs the Builder object.
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.survey_notification)
            .setContentText(context.getResources().getQuantityString(R.plurals.survey_notification_message,
                    surveys.size()))
            .setAutoCancel(true)
            .setContentTitle(context.getString(R.string.notifications_multi_title, surveys.size()))
            .setContentIntent(pi).setDeleteIntent(piDelete);

    if (!quiet) {
        builder.setDefaults(Notification.DEFAULT_ALL);
    }

    if (surveys.size() == 1) {
        Intent ignoreIntent = new Intent(context, NotifReceiver.class).setAction(ACTION_NOTIF_IGNORED)
                .putExtra(EXTRA_SURVEYS, surveys);
        PendingIntent piIgnore = PendingIntent.getBroadcast(context, 0, ignoreIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);

        Intent snoozeIntent = new Intent(context, NotifReceiver.class).setAction(ACTION_NOTIF_SNOOZED);
        PendingIntent piSnooze = PendingIntent.getBroadcast(context, 0, snoozeIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);

        builder.addAction(R.drawable.stat_notify_alarm, context.getString(R.string.snooze), piSnooze).addAction(
                android.R.drawable.ic_menu_close_clear_cancel, context.getString(R.string.ignore), piIgnore);

        // Get the survey name
        Cursor cursor = context.getContentResolver().query(Reminders.buildRemindersUri(),
                new String[] { Reminders.REMINDER_NAME }, Reminders._ID + "=?", new String[] { surveys.get(0) },
                null);
        if (cursor.moveToFirst()) {
            builder.setContentTitle(cursor.getString(0));
        }
    }
    notifMan.notify(NOIF_ID, builder.build());

    //Save the current visibility
    saveNotifVisibility(context, true);
}

From source file:seantool.SeanNotify.java

public void sentSimpleNotification(int iconResId, String title, String message) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setContentTitle(title)
            .setContentText(message);/*from  ww  w . j  av  a 2s .c  om*/

    if (iconResId == -1) {
        builder.setSmallIcon(android.R.drawable.ic_notification_overlay);
    } else {
        builder.setSmallIcon(iconResId);
    }

    builder.setPriority(Notification.PRIORITY_HIGH);
    builder.setDefaults(Notification.DEFAULT_ALL);

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

    manager.notify(0, builder.build());

}

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

public void createNotification(String notificationText, boolean onGoing, boolean headsUp) {
    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,
            headsUp ? PUSH_NOTIFICATION_CHANNEL : PERSISTENT_NOTIFICATION_CHANNEL)
                    .setContentTitle(//from ww  w  .  j a  v a  2 s  .c om
                            ApplicationLoader.applicationContext.getResources().getString(R.string.app_name))
                    .setContentText(notificationText).setContentIntent(pendingIntent)
                    .setSmallIcon(R.drawable.notifybar).setOngoing(onGoing).setAutoCancel(!onGoing)
                    .setStyle(new NotificationCompat.BigTextStyle().bigText(notificationText)).setColor(
                            ContextCompat.getColor(ApplicationLoader.applicationContext, R.color.colorPrimary));
    if (headsUp) {
        mBuilder.setPriority(NotificationCompat.PRIORITY_HIGH);
        mBuilder.setDefaults(Notification.DEFAULT_ALL);
    } else if (onGoing) {
        mBuilder.setPriority(NotificationCompat.PRIORITY_MIN);
    }
    mNotificationManager.notify(LESSON_NOTIFICATION_ID, mBuilder.build());
}

From source file:org.catnut.service.UpgradeService.java

private void checkout() throws Exception {
    URL url = new URL(METADATA_URL);
    InputStream inputStream = url.openStream();
    Scanner in = new Scanner(inputStream).useDelimiter("\\A");
    if (in.hasNext()) {
        JSONObject metadata = new JSONObject(in.next());
        PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), 0);
        if (info.versionCode < metadata.optInt(FIELD_VERSION_CODE)) {
            Notification.InboxStyle style = new Notification.InboxStyle(mBuilder);
            String size = metadata.optString("size");
            style.setBigContentTitle(getString(R.string.find_new_version, size));
            JSONArray messages = metadata.optJSONArray("messages");
            for (int i = 0; i < messages.length(); i++) {
                style.addLine(messages.optString(i));
            }/*from   w  ww. j  a v  a2 s . c  o m*/
            // download&upgrade intent
            Intent download = new Intent(this, UpgradeService.class);
            download.setAction(ACTION_DOWNLOAD);
            download.putExtra(DOWNLOAD_LINK, metadata.optString(DOWNLOAD_LINK));
            PendingIntent piDownload = PendingIntent.getService(this, 0, download, 0);
            mBuilder.addAction(R.drawable.ic_stat_download_dark, getString(R.string.down_load_and_upgrade),
                    piDownload);
            // dismiss notification
            Intent dismiss = new Intent(this, UpgradeService.class);
            dismiss.setAction(ACTION_DISMISS);
            PendingIntent piDismiss = PendingIntent.getService(this, 0, dismiss, 0);
            mBuilder.addAction(R.drawable.ic_stat_content_remove_dark, getString(R.string.not_upgrade_now),
                    piDismiss);
            // show it.
            mBuilder.setTicker(getString(R.string.find_new_version));
            mNotificationManager.notify(ID, mBuilder.setDefaults(Notification.DEFAULT_ALL).build());
        } else {
            new Handler(Looper.getMainLooper()).post(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(UpgradeService.this, getString(R.string.already_updated), Toast.LENGTH_SHORT)
                            .show();
                }
            });
        }
    }
    in.close();
}

From source file:com.arubadesignweb.app.appoverview.util.GcmIntentService.java

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

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, Application.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.setAutoCancel(true);/*from   www  .  j  ava 2s . c  om*/
    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());

    CommonUtilities.markAsDisplayed(extras.getString("message_id"));
}

From source file:com.arubadesignweb.app.appoverview.util.GcmIntentService.java

public static void sendLocalNotification(Context context, String title, String message, String message_id) {
    NotificationManager mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, Application.class),
            0);/*from   w w w  .j ava  2 s.c  o  m*/

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

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

    CommonUtilities.markAsDisplayed(message_id);
}