Example usage for android.app Notification DEFAULT_SOUND

List of usage examples for android.app Notification DEFAULT_SOUND

Introduction

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

Prototype

int DEFAULT_SOUND

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

Click Source Link

Document

Use the default notification sound.

Usage

From source file:il.ac.shenkar.todos.notifications.NotificationService.java

@Override
public void onHandleIntent(Intent intent) {
    taskListModel = TaskList.getSingletonObject(this);
    // Vibrate the mobile phone
    Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    //vibrator.vibrate(vibrationTime);
    vibrator.vibrate(vibrationTime);//w  w  w .  j  a v a2s  .c  om
    taskListModel.getDataBase().open();

    String[] tokens = intent.getStringExtra("description").split(",");
    taskId = Integer.parseInt(tokens[0]);
    String title = tokens[1];
    String windowTitle = null;
    String toSend = null;
    Task triggeredTask = null;
    boolean alarmRepeating = true;

    // check if alert was triggered by the location alert
    if (title.equals("GPS location nearby !")) {
        alarmType = "GPS";
        alarmRepeating = false;
        taskId = intent.getIntExtra("Id", 0);
        windowTitle = "GPS location nearby !";
        toSend = "Title: " + tokens[3] + "\n\nLocation: " + tokens[2];
        triggeredTask = Utils.findTaskById(this, taskId);

        if (triggeredTask != null) {
            // remove the alarm
            new TaskAlarms(this).cancelProximityAlert(taskId, triggeredTask.getTaskTitle());
            taskListModel.getDataBase().disableTaskLocationAlert(taskId);
        }
    } else // triggered by time alert
    {
        alarmType = "Time";
        windowTitle = "Notification";
        toSend = "Title: " + title + "\n\nDescription: " + tokens[2];
        triggeredTask = Utils.findTaskById(this, taskId);

        if (triggeredTask != null) {
            String taskNotification = triggeredTask.getDate();
            // checks if the alarm has an interval
            if (!taskNotification.contains("(")) {
                alarmRepeating = false;
                new TaskAlarms(this).cancelAlarm(taskId, triggeredTask.getTaskTitle());
                taskListModel.getDataBase().disableTaskNotification(taskId);
            }
        }
    }

    // Prepare intent which is triggered if the
    // notification is selected
    Intent myIntent = new Intent(this, NotificationReceiverActivity.class);
    myIntent.putExtra("windowTitle", windowTitle);
    myIntent.putExtra("taskContent", toSend);
    PendingIntent pIntent = PendingIntent.getActivity(this, taskId, myIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Build notification
    Notification noti = new Notification.Builder(this).setContentTitle(title).setContentText(tokens[2])
            .setSmallIcon(R.drawable.app_icon).setContentIntent(pIntent).build();

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    // Hide the notification after its selected
    noti.flags |= Notification.FLAG_AUTO_CANCEL;
    noti.flags |= Notification.FLAG_SHOW_LIGHTS;
    noti.ledARGB = 0xff00ffff;
    noti.ledOnMS = 300;
    noti.ledOffMS = 1000;

    if (Utils.IS_DEFAULT_SOUND) {
        //To play the default sound with your notification:
        noti.defaults |= Notification.DEFAULT_SOUND;
    } else {
        new MediaPlayerHandler(this).playAudio(Utils.LOUD_NOTIFICATION__SOUND);
    }
    notificationManager.notify(taskId, noti);

    if (!alarmRepeating) {
        // brodcast a message to main activity
        messageToActivity();
    }
}

From source file:fr.vassela.acrrd.notifier.TelephoneCallNotifier.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public void displayNotification(Context context, String ticker, String contentTitle, String contentText,
        boolean autoCancel, boolean ongoingEvent, boolean activateEvent) {
    try {/*from   ww  w. j  a  v a  2s  . c  o  m*/
        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
        boolean isPreferencesNotificationsActivated = sharedPreferences
                .getBoolean("preferences_notifications_activate", false);
        boolean isPreferencesNotificationsSoundActivated = sharedPreferences
                .getBoolean("preferences_notifications_sound_activate", false);
        boolean isPreferencesNotificationsVibrateActivated = sharedPreferences
                .getBoolean("preferences_notifications_vibrate_activate", false);
        boolean isPreferencesNotificationsLedActivated = sharedPreferences
                .getBoolean("preferences_notifications_led_activate", false);

        if (isPreferencesNotificationsActivated == true) {
            long notificationWhen = System.currentTimeMillis();
            int notificationDefaults = 0;

            Intent intent;

            if (ongoingEvent == true) {
                intent = new Intent(context, Main.class);
                intent.putExtra("setCurrentTab", "home");
            } else {
                intent = new Intent(SHOW_RECORDS);
            }

            PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

            NotificationManager notificationManager = (NotificationManager) context
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            Notification.Builder notificationBuilder = new Notification.Builder(context);

            if (ongoingEvent == false) {
                notificationBuilder.setWhen(notificationWhen);
            }

            if (isPreferencesNotificationsSoundActivated == true) {
                notificationDefaults = notificationDefaults | Notification.DEFAULT_SOUND;
            }

            if (isPreferencesNotificationsVibrateActivated == true) {
                notificationDefaults = notificationDefaults | Notification.DEFAULT_VIBRATE;
            }

            if (isPreferencesNotificationsLedActivated == true) {
                notificationDefaults = notificationDefaults | Notification.DEFAULT_LIGHTS;
            }

            if (ongoingEvent == false) {
                notificationBuilder.setDefaults(notificationDefaults);
            }

            if (activateEvent == true) {
                notificationBuilder.setSmallIcon(R.drawable.presence_audio_online);
            } else {
                notificationBuilder.setSmallIcon(R.drawable.presence_audio_busy);
            }

            if (ongoingEvent == false) {
                notificationBuilder.setTicker(ticker);
            }

            notificationBuilder.setContentTitle(contentTitle);
            notificationBuilder.setContentText(contentText);
            notificationBuilder.setContentIntent(pendingIntent);
            notificationBuilder.setAutoCancel(autoCancel);
            notificationBuilder.setOngoing(ongoingEvent);

            Notification notification = notificationBuilder.build();

            if (ongoingEvent == true) {
                notificationManager.notify(getOngoingNotificationId(), notification);
            } else {
                notificationManager.notify(getNotificationId(), notification);
            }
        }
    } catch (Exception e) {
        Log.w("TelephoneCallNotifier", "displayNotification : " + context.getApplicationContext()
                .getString(R.string.log_telephone_call_notifier_error_display_notification) + " : " + e);
        databaseManager.insertLog(context.getApplicationContext(),
                "" + context.getApplicationContext()
                        .getString(R.string.log_telephone_call_notifier_error_display_notification),
                new Date().getTime(), 2, false);
    }
}

From source file:com.kinoma.kinomaplay.GcmIntentService.java

private void sendNotification(JSONObject json) {
    if (mNotificationManager == null) {
        mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    }//from  ww w .ja  v a2s.  c  om

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

    String title, message;
    try {
        title = json.getString(GCM_TITLE_KEY);
    } catch (Exception e) {
        title = "Kinoma Play";
    }
    try {
        message = json.getString(GCM_MESSAGE_KEY);
    } catch (Exception e) {
        message = "GCM received";
    }

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.icon)
            .setTicker(message).setContentTitle(title)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(message)).setContentText(message);

    SharedPreferences prefs = getPreferences();
    int notifType = prefs.getInt(KinomaPlay.kRemoteNotificationTypeKey, 0);
    Log.i("Kinoma", "RemoteNotificationType: " + notifType);

    if ((notifType & 2) != 0) {
        Log.i("Kinoma", "Notification with sound");
        mBuilder.setDefaults(Notification.DEFAULT_SOUND);
    }

    mBuilder.setContentIntent(contentIntent);
    mBuilder.setAutoCancel(true);
    mNotificationManager.notify(KinomaPlay.kNotificationIDRemote, mBuilder.build());
}

From source file:com.example.mego.adas.utils.NotificationUtils.java

/**
 * Helper Method to create and display accident notification
 *
 * @param context//from w  w w.ja  va  2 s  .c  o m
 */
public static void showAccidentNotification(Context context) {
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
            .setColor(ContextCompat.getColor(context, R.color.colorPrimary)).setSmallIcon(R.mipmap.ic_launcher)
            .setLargeIcon(largeIcon(context)).setContentTitle(context.getString(R.string.notification_accident))
            .setContentText(context.getString(R.string.car_accident))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(context.getString(R.string.car_accident)))
            .setDefaults(Notification.DEFAULT_VIBRATE).setDefaults(Notification.DEFAULT_SOUND)
            .setContentIntent(contentIntent(context)).setAutoCancel(true);

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

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

    notificationManager.notify(ADAS_ACCIDENT_NOTIFICATION_ID, notificationBuilder.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   ww w  . j  a  va 2  s . co 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:com.baochu.androidassignment.notification.GcmIntentService.java

/** Issues a notification to inform the user */
private void sendNotification(String msg) {
    int msgId = Utils.getMessageId();
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    Intent intent = new Intent(this, MainActivity.class);
    // set intent so it does not start a new activity
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    intent.putExtra(GcmActivity.EXTRA_MESSAGE, msg);
    PendingIntent contentIntent = PendingIntent.getActivity(this, msgId, intent, 0);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_gcm).setContentTitle(this.getString(R.string.app_name))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg)
            .setDefaults(Notification.DEFAULT_SOUND).setAutoCancel(true);

    builder.setContentIntent(contentIntent);
    mNotificationManager.notify(msgId, builder.build());
}

From source file:name.gudong.translate.listener.view.TipViewController.java

public void show(Result result, boolean isShowFavoriteButton, boolean isShowDoneMark,
        TipView.ITipViewListener mListener) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
    boolean isSettingUseSystemNotification = sharedPreferences
            .getBoolean("preference_show_float_view_use_system", false);
    if (Utils.isSDKHigh5() && isSettingUseSystemNotification) {
        StringBuilder sb = new StringBuilder();
        for (String string : result.getExplains()) {
            sb.append(string).append("\n");
        }//from w ww  . j a va  2  s  . c om

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext)
                .setSmallIcon(R.drawable.icon_notification).setContentTitle(result.getQuery())
                .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND)
                .setVibrate(new long[] { 0l }).setPriority(Notification.PRIORITY_HIGH)
                .setContentText(sb.toString());

        /* Add Big View Specific Configuration */
        NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();

        // Moves events into the big view
        for (String string : result.getExplains()) {
            inboxStyle.addLine(string);
        }

        mBuilder.setStyle(inboxStyle);

        Intent resultIntent = new Intent(mContext, MainActivity.class);
        resultIntent.putExtra("data", result);

        PendingIntent resultPendingIntent = PendingIntent.getActivity(mContext, 0, resultIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        mBuilder.addAction(R.drawable.ic_favorite_border_grey_24dp, "?", resultPendingIntent);
        NotificationManager mNotificationManager = (NotificationManager) mContext
                .getSystemService(Context.NOTIFICATION_SERVICE);
        Notification note = mBuilder.build();
        mNotificationManager.notify(result.getQuery().hashCode(), note);

    } else {
        TipView tipView = new TipView(mContext);
        mMapTipView.put(result, tipView);
        tipView.setListener(mListener);
        mWindowManager.addView(tipView, getPopViewParams());
        tipView.startWithAnim();
        tipView.setContent(result, isShowFavoriteButton, isShowDoneMark);
        closeTipViewCountdown(tipView, mListener);
    }
}

From source file:com.moxtra.moxiechat.GcmIntentService.java

private void sendMoxtraNotification(String msg, Uri uri, Intent intent) {
    Log.d(TAG, "Got notification: msg = " + msg + ", uri = " + uri);
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    PendingIntent contentIntent = MXNotificationManager.getMXNotificationIntent(this, intent, 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_mc_notification)
            .setContentTitle(getString(getApplicationInfo().labelRes))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg)
            .setAutoCancel(true).setDefaults(
                    Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE);

    if (uri != null) {
        mBuilder.setSound(uri);/*  w  ww  .jav  a 2  s.  c  o m*/
    }

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

From source file:org.andicar.service.UpdateCheckService.java

@Override
public void onStart(Intent intent, int startId) {
    super.onStart(intent, startId);

    if (getSharedPreferences(StaticValues.GLOBAL_PREFERENCE_NAME, Context.MODE_MULTI_PROCESS)
            .getBoolean("SendCrashReport", true))
        Thread.setDefaultUncaughtExceptionHandler(
                new AndiCarExceptionHandler(Thread.getDefaultUncaughtExceptionHandler(), this));

    try {/*from  w  ww  . j av  a2 s. c  o m*/
        Bundle extras = intent.getExtras();
        if (extras == null || extras.getBoolean("setJustNextRun") || !extras.getBoolean("AutoUpdateCheck")) {
            setNextRun();
            stopSelf();
        }

        URL updateURL = new URL(StaticValues.VERSION_FILE_URL);
        URLConnection conn = updateURL.openConnection();
        if (conn == null)
            return;
        InputStream is = conn.getInputStream();
        if (is == null)
            return;
        BufferedInputStream bis = new BufferedInputStream(is);
        ByteArrayBuffer baf = new ByteArrayBuffer(50);
        int current = 0;
        while ((current = bis.read()) != -1) {
            baf.append((byte) current);
        }

        /* Convert the Bytes read to a String. */
        String s = new String(baf.toByteArray());
        /* Get current Version Number */
        int curVersion = getPackageManager().getPackageInfo("org.andicar.activity", 0).versionCode;
        int newVersion = Integer.valueOf(s);

        /* Is a higher version than the current already out? */
        if (newVersion > curVersion) {
            //get the whats new message
            updateURL = new URL(StaticValues.WHATS_NEW_FILE_URL);
            conn = updateURL.openConnection();
            if (conn == null)
                return;
            is = conn.getInputStream();
            if (is == null)
                return;
            bis = new BufferedInputStream(is);
            baf = new ByteArrayBuffer(50);
            current = 0;
            while ((current = bis.read()) != -1) {
                baf.append((byte) current);
            }

            /* Convert the Bytes read to a String. */
            s = new String(baf.toByteArray());

            mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            notification = null;
            Intent i = new Intent(this, WhatsNewDialog.class);
            i.putExtra("UpdateMsg", s);
            PendingIntent contentIntent = PendingIntent.getActivity(UpdateCheckService.this, 0, i, 0);

            CharSequence title = getText(R.string.Notif_UpdateTitle);
            String message = getString(R.string.Notif_UpdateMsg);
            notification = new Notification(R.drawable.icon_sys_info, message, System.currentTimeMillis());
            notification.flags |= Notification.DEFAULT_LIGHTS;
            notification.flags |= Notification.DEFAULT_SOUND;
            notification.flags |= Notification.FLAG_AUTO_CANCEL;
            notification.setLatestEventInfo(UpdateCheckService.this, title, message, contentIntent);
            mNM.notify(StaticValues.NOTIF_UPDATECHECK_ID, notification);
            setNextRun();
        }
        stopSelf();
    } catch (Exception e) {
        Log.i("UpdateService", "Service failed.");
        e.printStackTrace();
    }
}

From source file:com.scoreflex.ScoreflexGcmClient.java

protected static Notification buildNotification(String text, Context context, int iconResource,
        PendingIntent pendingIntent) {//www.j a  v  a 2 s .  c  om
    final PackageManager pm = context.getApplicationContext().getPackageManager();
    ApplicationInfo ai;
    try {
        ai = pm.getApplicationInfo(context.getPackageName(), 0);
    } catch (final NameNotFoundException e) {
        ai = null;
    }
    final String applicationName = (String) (ai != null ? pm.getApplicationLabel(ai) : "(unknown)");
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setContentTitle(applicationName).setContentText(text).setSmallIcon(iconResource);

    mBuilder.setContentIntent(pendingIntent);
    Notification notification = mBuilder.build();
    notification.defaults = Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE;
    notification.flags = Notification.FLAG_AUTO_CANCEL;
    return notification;
}