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.commonsware.android.okhttp3.progress.Downloader.java

private void raiseNotification(String contentType, File output, Exception e) {
    NotificationCompat.Builder b = new NotificationCompat.Builder(this);

    b.setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL).setWhen(System.currentTimeMillis());

    if (e == null) {
        b.setContentTitle(getString(R.string.download_complete)).setContentText(getString(R.string.fun))
                .setSmallIcon(android.R.drawable.stat_sys_download_done)
                .setTicker(getString(R.string.download_complete));

        Intent outbound = new Intent(Intent.ACTION_VIEW);

        outbound.setDataAndType(Uri.fromFile(output), contentType);

        b.setContentIntent(PendingIntent.getActivity(this, 0, outbound, 0));
    } else {/*from  w  ww. j a  v  a 2 s . c o m*/
        b.setContentTitle(getString(R.string.exception)).setContentText(e.getMessage())
                .setSmallIcon(android.R.drawable.stat_notify_error).setTicker(getString(R.string.exception));
    }

    mgr.notify(NOTIFY_ID, b.build());
}

From source file:conversandroid.cookingnotifications.MainActivity.java

/**
 * Simple notification: only title and text, no actions attached
 *///from   w ww .ja v a 2s . c  o m
private void showSimpleNotification() {
    int notificationId = 1;

    //Building notification layout
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.cook).setContentTitle("Time for lunch!")
            .setDefaults(Notification.DEFAULT_ALL) //Beware that without some default behaviours
            //the notification may not show up in the wearable
            .setContentText("Your lunch is ready");

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

    // Building the notification and issuing it with the notification manager
    notificationManager.notify(notificationId, notificationBuilder.build());

}

From source file:com.binil.pushnotification.GcmIntentService.java

private void displayNotification(PendingIntent pi, String title, String msg) {

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher)
            .setLargeIcon(((BitmapDrawable) ContextCompat.getDrawable(getApplication(), R.drawable.ic_launcher))
                    .getBitmap())//from www .j  a v  a 2 s  .  c om
            .setContentTitle(title).setContentText(msg).setContentIntent(pi).setTicker(msg)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setAutoCancel(true)
            .setDefaults(Notification.DEFAULT_ALL);

    NotificationManagerCompat manager = NotificationManagerCompat.from(getApplicationContext());
    manager.notify(NOTIFICATION_ID, mBuilder.build());
}

From source file:com.joulespersecond.seattlebusbot.tripservice.NotifierTask.java

private Notification createNotification(PendingIntent deleteIntent) {
    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(deleteIntent).build();
}

From source file:org.zywx.wbpalmstar.platform.push.PushRecieveMsgReceiver.java

private void buildPushNotification(Context context, Intent intent, PushDataInfo dataInfo) {
    String title = dataInfo.getTitle();
    String body = dataInfo.getAlert();
    String message = dataInfo.getPushDataString();
    Builder builder = new Builder(context);
    builder.setAutoCancel(true);//from www . j av a  2 s.  c  o  m
    builder.setContentTitle(title); // 
    builder.setContentText(body); // 
    builder.setTicker(body); // ??

    String[] remindType = dataInfo.getRemindType();
    if (remindType != null) {
        if (remindType.length == 3) {
            builder.setDefaults(Notification.DEFAULT_ALL);
        } else {
            int defaults = 0;
            for (int i = 0; i < remindType.length; i++) {
                if ("sound".equalsIgnoreCase(remindType[i])) {
                    defaults = Notification.DEFAULT_SOUND;
                    continue;
                }
                if ("shake".equalsIgnoreCase(remindType[i])) {
                    defaults = defaults | Notification.DEFAULT_VIBRATE;
                    continue;
                }
                if ("breathe".equalsIgnoreCase(remindType[i])) {
                    defaults = defaults | Notification.DEFAULT_LIGHTS;
                    continue;
                }
            }
            builder.setDefaults(defaults);
        }
    }

    Resources res = context.getResources();
    int icon = res.getIdentifier("icon", "drawable", intent.getPackage());
    builder.setSmallIcon(icon);
    builder.setWhen(System.currentTimeMillis()); // 

    String iconUrl = dataInfo.getIconUrl();
    boolean isDefaultIcon = !TextUtils.isEmpty(iconUrl) && "default".equalsIgnoreCase(iconUrl);
    Bitmap bitmap = null;
    if (!isDefaultIcon) {
        bitmap = getIconBitmap(context, iconUrl);
    }
    String fontColor = dataInfo.getFontColor();
    RemoteViews remoteViews = null;
    if (!TextUtils.isEmpty(fontColor)) {
        int color = BUtility.parseColor(fontColor);
        int alphaColor = parseAlphaColor(fontColor);
        remoteViews = new RemoteViews(intent.getPackage(), EUExUtil.getResLayoutID("push_notification_view"));
        // Title
        remoteViews.setTextViewText(EUExUtil.getResIdID("notification_title"), title);
        remoteViews.setTextColor(EUExUtil.getResIdID("notification_title"), color);
        // Body
        remoteViews.setTextViewText(EUExUtil.getResIdID("notification_body"), body);
        remoteViews.setTextColor(EUExUtil.getResIdID("notification_body"), alphaColor);
        // LargeIcon
        if (bitmap != null) {
            remoteViews.setImageViewBitmap(EUExUtil.getResIdID("notification_largeIcon"), bitmap);
        } else {
            remoteViews.setImageViewResource(EUExUtil.getResIdID("notification_largeIcon"),
                    EUExUtil.getResDrawableID("icon"));
        }
        // Time
        SimpleDateFormat format = new SimpleDateFormat("HH:mm");
        remoteViews.setTextViewText(EUExUtil.getResIdID("notification_time"),
                format.format(System.currentTimeMillis()));
        remoteViews.setTextColor(EUExUtil.getResIdID("notification_time"), alphaColor);
        builder.setContent(remoteViews);
    }

    Intent notiIntent = new Intent(context, EBrowserActivity.class);
    notiIntent.putExtra("ntype", F_TYPE_PUSH);
    notiIntent.putExtra("data", body);
    notiIntent.putExtra("message", message);
    Bundle bundle = new Bundle();
    bundle.putSerializable(PushReportConstants.PUSH_DATA_INFO_KEY, dataInfo);
    notiIntent.putExtras(bundle);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, notificationNB, notiIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(pendingIntent);

    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = builder.build();
    // Android v4bug2.3?Builder?NotificationRemoteView??
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB && remoteViews != null) {
        notification.contentView = remoteViews;
    }
    manager.notify(notificationNB, notification);
    notificationNB++;
}

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

private void download(Intent intent) throws IOException {
    String link = intent.getExtras().getString(DOWNLOAD_LINK);
    URL url = new URL(link);
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    File apk = new File(getExternalCacheDir().getPath() + "/" + Uri.parse(link).getLastPathSegment());
    FileOutputStream outputStream = new FileOutputStream(apk);
    InputStream inputStream = new BufferedInputStream(connection.getInputStream());

    connection.connect();/*from   ww  w  . j  a  v  a 2 s. co  m*/
    int length = connection.getContentLength();

    byte[] buffer = new byte[1024];
    int tmp;
    int count = 0;
    mBuilder.setContentTitle(getString(R.string.download_apk));
    mBuilder.setContentText(getString(R.string.downloading));
    while ((tmp = inputStream.read(buffer)) != -1) {
        count += tmp;
        outputStream.write(buffer, 0, tmp);
        mBuilder.setProgress(100, (int) ((count * 1.f / length) * 100), true);
        mNotificationManager.notify(ID, mBuilder.build());
    }
    inputStream.close();
    outputStream.close();
    connection.disconnect();

    Intent install = new Intent(Intent.ACTION_VIEW);
    install.setDataAndType(Uri.fromFile(apk), "application/vnd.android.package-archive");
    PendingIntent piInstall = PendingIntent.getActivity(this, 0, install, 0);
    mBuilder.setProgress(0, 0, false);
    mBuilder.setContentIntent(piInstall);

    mBuilder.setTicker(getString(R.string.done_download)).setContentTitle(getString(R.string.done_download))
            .setContentText(getString(R.string.click_to_upgrade));
    mNotificationManager.notify(ID, mBuilder.setDefaults(Notification.DEFAULT_ALL).build());
}

From source file:com.becapps.easydownloader.utils.Utils.java

public static void setNotificationDefaults(NotificationCompat.Builder aBuilder) {
    String def = settings.getString("notification_defaults", "0");
    if (def.equals("0")) {
        aBuilder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
    }/*ww w.  j  a v a2s  .  com*/
    if (def.equals("1")) {
        aBuilder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS);
    }
    if (def.equals("2")) {
        aBuilder.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE);
    }
    if (def.equals("3")) {
        aBuilder.setDefaults(Notification.DEFAULT_ALL);
    }
    if (def.equals("4")) {
        aBuilder.setDefaults(Notification.DEFAULT_SOUND);
    }
    if (def.equals("5")) {
        aBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
    }
    if (def.equals("6")) {
        aBuilder.setDefaults(Notification.DEFAULT_LIGHTS);
    }
    if (def.equals("7")) {
        // nothing...
    }
}

From source file:jackpal.androidterm.TermService.java

@Override
public void onCreate() {
    // should really belong to the Application class, but we don't use one...
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    SharedPreferences.Editor editor = prefs.edit();
    String defValue = getDir("HOME", MODE_PRIVATE).getAbsolutePath();
    String homePath = prefs.getString("home_path", defValue);
    editor.putString("home_path", homePath);
    editor.commit();//ww  w  .  j  av a 2  s . co m
    compat = new ServiceForegroundCompat(this);
    mTermSessions = new SessionList();

    /* Put the service in the foreground. */
    // Define the bounds in which the Activity will be launched into.
    Intent notifyIntent = new Intent(this, Term.class);
    notifyIntent.addFlags(NotificationCompat.FLAG_ONGOING_EVENT);
    notifyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notifyIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setSmallIcon(R.drawable.ic_stat_service_notification_icon);
    builder.setWhen(System.currentTimeMillis());
    Notification simpleNotice = builder.setContentText(getString(R.string.service_notify_text))
            .setContentText(getString(R.string.service_notify_text))
            .setSmallIcon(R.drawable.ic_stat_service_notification_icon).setContentIntent(pendingIntent)
            .setAutoCancel(true).setDefaults(Notification.DEFAULT_ALL).setPriority(Notification.PRIORITY_HIGH)
            .build();
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(0, simpleNotice);

    Log.d(TermDebug.LOG_TAG, "TermService started");
    return;
}

From source file:edu.worcester.cs499summer2012.service.NotificationHelper.java

/**
 * Basic Text Notification with Ongoing flag enabled for Task Butler, using NotificationCompat
 * @param context /*from  w  w w .  j  av a  2s  . 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_notification
                    : R.drawable.ic_notification_deprecated)
            .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:com.androidbegin.gcmtutorial.GcmIntentService.java

private void sendNotification(String msg) {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    Intent i = new Intent(this, GCMMainActivity.class);
    i.putExtra("message", msg);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, 0);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle("GCM Notification")
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg)
            .setDefaults(Notification.DEFAULT_ALL);

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