Example usage for android.app Notification DEFAULT_VIBRATE

List of usage examples for android.app Notification DEFAULT_VIBRATE

Introduction

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

Prototype

int DEFAULT_VIBRATE

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

Click Source Link

Document

Use the default notification vibrate.

Usage

From source file:com.meiste.greg.ptw.RaceAlarm.java

@Override
protected void onHandleIntent(final Intent intent) {
    alarm_set = false;// w  w  w  .j  a va2s.  co  m
    final Race race = Race.getInstance(this, intent.getIntExtra(RACE_ID, 0));
    Util.log("Received race alarm for race " + race.getId());

    synchronized (mSync) {
        if (mContainer == null) {
            try {
                mSync.wait();
            } catch (final InterruptedException e) {
            }
        }
    }

    // Only show notification if user wants race reminders
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    if (prefs.getBoolean(EditPreferences.KEY_NOTIFY_RACE, true)
            && mContainer.getBoolean(GtmHelper.KEY_GAME_ENABLED)) {
        final Intent notificationIntent = new Intent(this, RaceActivity.class);
        notificationIntent.putExtra(RaceActivity.INTENT_ID, race.getId());
        notificationIntent.putExtra(RaceActivity.INTENT_ALARM, true);
        final PendingIntent pi = PendingIntent.getActivity(this, PI_REQ_CODE, notificationIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);

        int defaults = 0;
        if (prefs.getBoolean(EditPreferences.KEY_NOTIFY_VIBRATE, true))
            defaults |= Notification.DEFAULT_VIBRATE;
        if (prefs.getBoolean(EditPreferences.KEY_NOTIFY_LED, true))
            defaults |= Notification.DEFAULT_LIGHTS;

        final NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_stat_steering_wheel)
                .setTicker(getString(R.string.remind_race_ticker, race.getName()))
                .setContentTitle(getString(R.string.remind_race_notify)).setContentText(race.getName())
                .setContentIntent(pi).setAutoCancel(true).setDefaults(defaults).setSound(Uri
                        .parse(prefs.getString(EditPreferences.KEY_NOTIFY_RINGTONE, PTW.DEFAULT_NOTIFY_SND)));

        getNM(this).notify(R.string.remind_race_ticker, builder.build());
    } else {
        Util.log("Ignoring race alarm since option is disabled");
    }

    // Reset alarm for the next race
    set(this);
    sendBroadcast(new Intent(PTW.INTENT_ACTION_RACE_ALARM));
}

From source file:com.tenmiles.helpstack.service.AttachmentDownloadReceiver.java

private void downloadCompleted(Context context, Intent intent) {
    StringBuilder text = new StringBuilder();
    //Files are  ready
    String filename = context.getString(R.string.hs_attachment);
    String filepath = null;/*from  www  .  j a v a2s. c  o m*/
    String mediaType = null;
    DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
    long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
    Query query = new Query();
    query.setFilterById(downloadId);
    Cursor c = dm.query(query);
    if (c.moveToFirst()) {
        int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
        filename = c.getString(c.getColumnIndex(DownloadManager.COLUMN_TITLE));
        filepath = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
        mediaType = c.getString(c.getColumnIndex(DownloadManager.COLUMN_MEDIA_TYPE));
        if (status == DownloadManager.STATUS_SUCCESSFUL) {
            text.append(context.getString(R.string.hs_download_complete));

        } else {
            text.append(context.getString(R.string.hs_error_during_download));
        }
    }

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

    NotificationCompat.Builder notificationbuilder = new NotificationCompat.Builder(context);
    notificationbuilder.setAutoCancel(true);
    notificationbuilder.setContentText(text.toString());
    notificationbuilder.setContentTitle(filename);
    notificationbuilder.setSmallIcon(R.drawable.hs_notification_download_img);
    notificationbuilder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
    notificationbuilder.setContentIntent(getPendingIntent(context));

    notificationManager.notify(filename, NOTIFICATION_ID, notificationbuilder.build());
}

From source file:ru.appsm.inapphelp.service.AttachmentDownloadReceiver.java

private void downloadCompleted(Context context, Intent intent) {
    StringBuilder text = new StringBuilder();
    //Files are  ready
    String filename = context.getString(R.string.iah_attachment);
    String filepath = null;//from  w ww . j  a  va  2 s. c o m
    String mediaType = null;
    DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
    long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
    Query query = new Query();
    query.setFilterById(downloadId);
    Cursor c = dm.query(query);
    if (c.moveToFirst()) {
        int status = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
        filename = c.getString(c.getColumnIndex(DownloadManager.COLUMN_TITLE));
        filepath = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
        mediaType = c.getString(c.getColumnIndex(DownloadManager.COLUMN_MEDIA_TYPE));
        if (status == DownloadManager.STATUS_SUCCESSFUL) {
            text.append(context.getString(R.string.iah_download_complete));

        } else {
            text.append(context.getString(R.string.iah_error_during_download));
        }
    }

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

    NotificationCompat.Builder notificationbuilder = new NotificationCompat.Builder(context);
    notificationbuilder.setAutoCancel(true);
    notificationbuilder.setContentText(text.toString());
    notificationbuilder.setContentTitle(filename);
    notificationbuilder.setSmallIcon(R.drawable.iah_notification_download_light_img);
    notificationbuilder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
    notificationbuilder.setContentIntent(getPendingIntent(context));

    notificationManager.notify(filename, NOTIFICATION_ID, notificationbuilder.build());
}

From source file:francesco.workspace.homeapp.GcmIntentService.java

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

    if (extras.containsKey("notification_type")) {
        NotificationCompat.Builder build = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_iconphone).setContentTitle("TapEvent - New Group!")
                .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setAutoCancel(true)
                .setContentText(msg).setLights(Color.BLUE, 300, 100).setDefaults(Notification.DEFAULT_VIBRATE);

        mNotificationManager.notify(NOTIFICATION_ID, build.build());

        return;/*from  w  w w  .j av  a2s .  c  o  m*/
    }

    Intent intent = new Intent(this, Event_details_invitation.class);
    Event_App ev = new Event_App(extras.getString("event_key"), extras.getString("event_name"),
            extras.getString("event_date"), extras.getString("event_hour"), extras.getString("event_user"),
            extras.getString("event_address"), extras.getString("event_location"),
            extras.getString("event_description"));

    ev.setState("false");
    intent.putExtra("singleEvent", ev);

    Intent intent_accept = new Intent();
    Intent intent_refuse = new Intent();

    intent_accept.putExtra("singleEvent", ev);
    intent_refuse.putExtra("singleEvent", ev);
    intent_accept.setAction(ACCEPT_INTENT);
    intent_refuse.setAction(REFUSE_INTENT);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_iconphone).setContentTitle("TapEvent - New Invitation!")
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setAutoCancel(true)
            .setContentText(msg)
            .addAction(R.drawable.ok_48_blue, "Accept",
                    PendingIntent.getBroadcast(this, 1234, intent_accept, PendingIntent.FLAG_CANCEL_CURRENT))
            .addAction(R.drawable.delete_64_red, "Refuse",
                    PendingIntent.getBroadcast(this, 1234, intent_refuse, PendingIntent.FLAG_CANCEL_CURRENT))
            .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE);

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

From source file:com.procasy.dubarah_nocker.gcm.MyGcmPushReceiver.java

/**
 * Called when message is received./*from  www.j  av  a2  s  .c o m*/
 *
 * @param from   SenderID of the sender.
 * @param bundle Data bundle containing message data as key/value pairs.
 *               For Set of keys use data.keySet().
 */

@Override
public void onMessageReceived(String from, Bundle bundle) {

    MainActivity.getInstance().updateNotification();

    try {

        Log.e("notify_gcm", "success , type = " + bundle.toString());

        switch (bundle.getString(GCM_TAG)) {
        case "GENERAL": {
            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.hourly_logo).setContentTitle(bundle.getString(TITLE_TAG))
                    .setContentText(bundle.getString(DESC_TAG));
            Intent resultIntent = new Intent(this, MainActivity.class);
            TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
            stackBuilder.addParentStack(MainActivity.class);
            stackBuilder.addNextIntent(resultIntent);
            PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            mBuilder.setContentIntent(resultPendingIntent);
            mBuilder.setDefaults(
                    Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE);
            NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                    Context.NOTIFICATION_SERVICE);
            mNotificationManager.notify(12, mBuilder.build());
            mNotification = new com.procasy.dubarah_nocker.Helper.Notification(getApplicationContext());
            mNotification.open();
            try {
                ContentValues contentValues = new ContentValues();
                contentValues.put(mNotification.COL_notification_type, GENERAL_TAG);
                contentValues.put(mNotification.COL_notfication_status, 0);
                contentValues.put(mNotification.COL_notfication_title, bundle.getString(TITLE_TAG));
                contentValues.put(mNotification.COL_notfication_desc, bundle.getString(DESC_TAG));
                contentValues.put(mNotification.COL_notfication_content, bundle.getString(CONTENT_TAG));
                mNotification.insertEntry(contentValues);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                mNotification.close();
            }
            break;
        }

        case "HELP": {
            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.hourly_logo).setContentTitle(bundle.getString(TITLE_TAG))
                    .setContentText(bundle.getString(DESC_TAG));
            Intent resultIntent = new Intent(this, MainActivity.class);
            TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
            stackBuilder.addParentStack(MainActivity.class);
            stackBuilder.addNextIntent(resultIntent);
            PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            mBuilder.setContentIntent(resultPendingIntent);
            mBuilder.setDefaults(
                    Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE);
            NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                    Context.NOTIFICATION_SERVICE);
            mNotificationManager.notify(12, mBuilder.build());
            mNotification = new com.procasy.dubarah_nocker.Helper.Notification(getApplicationContext());
            mNotification.open();
            try {
                ContentValues contentValues = new ContentValues();
                contentValues.put(mNotification.COL_notification_type, HELP_TAG);
                contentValues.put(mNotification.COL_notfication_status, 0);
                contentValues.put(mNotification.COL_notfication_title, bundle.getString(TITLE_TAG));
                contentValues.put(mNotification.COL_notfication_desc, bundle.getString(DESC_TAG));
                contentValues.put(mNotification.COL_notfication_content, bundle.getString(CONTENT_TAG));
                mNotification.insertEntry(contentValues);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                mNotification.close();
            }
            JSONObject content = new JSONObject(bundle.getString("content"));
            JSONObject hr = content.getJSONObject("hr");
            JSONArray album = content.getJSONArray("album");
            System.out.println(content.getInt("hr_id"));
            System.out.println(content.toString());
            Bundle bundle1 = new Bundle();
            bundle1.putString("hr_id", hr.getString("hr_id"));
            bundle1.putString("hr_user_id", hr.getString("hr_user_id"));
            bundle1.putString("hr_description", hr.getString("hr_description"));
            bundle1.putString("hr_est_date", hr.getString("hr_est_date"));
            bundle1.putString("hr_est_time", hr.getString("hr_est_time"));
            bundle1.putString("hr_skill_id", hr.getString("hr_skill_id"));
            bundle1.putString("hr_ua_id", hr.getString("hr_ua_id"));
            bundle1.putString("hr_voice_record", hr.getString("hr_voice_record"));
            bundle1.putString("hr_language", hr.getString("hr_language"));
            bundle1.putString("hr_lat", hr.getString("hr_lat"));
            bundle1.putString("hr_lon", hr.getString("hr_lon"));
            bundle1.putString("hr_address", hr.getString("hr_address"));
            ArrayList<String> array = new ArrayList<>();
            for (int i = 0; i < album.length(); i++) {
                JSONObject object = album.getJSONObject(i);
                array.add(object.getString("ahr_img"));
            }
            bundle1.putStringArrayList("album", array);

            Intent intent = (new Intent(getApplicationContext(), JobRequestActivity.class));
            intent.putExtras(bundle1);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            getApplicationContext().startActivity(intent);

            break;
        }

        case "APPOINTEMENT": {
            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.hourly_logo).setContentTitle(bundle.getString(TITLE_TAG))
                    .setContentText(bundle.getString(DESC_TAG));
            Intent resultIntent = new Intent(this, MainActivity.class);
            TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
            stackBuilder.addParentStack(MainActivity.class);
            stackBuilder.addNextIntent(resultIntent);
            PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            mBuilder.setContentIntent(resultPendingIntent);
            mBuilder.setDefaults(
                    Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE);
            NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                    Context.NOTIFICATION_SERVICE);
            mNotificationManager.notify(12, mBuilder.build());
            mNotification = new com.procasy.dubarah_nocker.Helper.Notification(getApplicationContext());
            mNotification.open();
            try {
                ContentValues contentValues = new ContentValues();
                contentValues.put(mNotification.COL_notification_type, APPOINTEMENT_TAG);
                contentValues.put(mNotification.COL_notfication_status, 0);
                contentValues.put(mNotification.COL_notfication_title, bundle.getString(TITLE_TAG));
                contentValues.put(mNotification.COL_notfication_desc, bundle.getString(DESC_TAG));
                contentValues.put(mNotification.COL_notfication_content, bundle.getString(CONTENT_TAG));
                mNotification.insertEntry(contentValues);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                mNotification.close();
            }
            break;
        }

        case "QOUTA_USER": {
            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.hourly_logo).setContentTitle(bundle.getString(TITLE_TAG))
                    .setContentText(bundle.getString(DESC_TAG));
            Intent resultIntent = new Intent(this, MainActivity.class);
            TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
            stackBuilder.addParentStack(MainActivity.class);
            stackBuilder.addNextIntent(resultIntent);
            PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            mBuilder.setContentIntent(resultPendingIntent);
            mBuilder.setDefaults(
                    Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE);
            NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                    Context.NOTIFICATION_SERVICE);
            mNotificationManager.notify(12, mBuilder.build());
            mNotification = new com.procasy.dubarah_nocker.Helper.Notification(getApplicationContext());
            mNotification.open();
            try {
                ContentValues contentValues = new ContentValues();
                contentValues.put(mNotification.COL_notification_type, USER_Qouta_TAG);
                contentValues.put(mNotification.COL_notfication_status, 0);
                contentValues.put(mNotification.COL_notfication_title, bundle.getString(TITLE_TAG));
                contentValues.put(mNotification.COL_notfication_desc, bundle.getString(DESC_TAG));
                contentValues.put(mNotification.COL_notfication_content, bundle.getString(CONTENT_TAG));
                mNotification.insertEntry(contentValues);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                mNotification.close();
            }
            break;
        }

        case "QOUTA_NOCKER": {
            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.hourly_logo).setContentTitle(bundle.getString(TITLE_TAG))
                    .setContentText(bundle.getString(DESC_TAG));
            Intent resultIntent = new Intent(this, MainActivity.class);
            TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
            stackBuilder.addParentStack(MainActivity.class);
            stackBuilder.addNextIntent(resultIntent);
            PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            mBuilder.setContentIntent(resultPendingIntent);
            mBuilder.setDefaults(
                    Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE);
            NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                    Context.NOTIFICATION_SERVICE);
            mNotificationManager.notify(12, mBuilder.build());
            mNotification = new com.procasy.dubarah_nocker.Helper.Notification(getApplicationContext());
            mNotification.open();
            try {
                ContentValues contentValues = new ContentValues();
                contentValues.put(mNotification.COL_notification_type, Nocker_Qouta_TAG);
                contentValues.put(mNotification.COL_notfication_status, 0);
                contentValues.put(mNotification.COL_notfication_title, bundle.getString(TITLE_TAG));
                contentValues.put(mNotification.COL_notfication_desc, bundle.getString(DESC_TAG));
                contentValues.put(mNotification.COL_notfication_content, bundle.getString(CONTENT_TAG));
                mNotification.insertEntry(contentValues);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                mNotification.close();
            }
            break;
        }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.asb.spandan2014.GcmIntentService.java

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

    Intent resultIntent = new Intent(this, AlertsActivity.class);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    // Adds the back stack
    stackBuilder.addParentStack(AlertsActivity.class);
    // Adds the Intent to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    // Gets a PendingIntent containing the entire back stack
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.alerts)
            .setContentTitle(getString(R.string.spandan_update))
            .setDefaults(Notification.DEFAULT_VIBRATE | Notification.FLAG_SHOW_LIGHTS
                    | Notification.FLAG_AUTO_CANCEL | Notification.DEFAULT_LIGHTS)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg);

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

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

/**
 * Helper Method to create and display accident notification
 *
 * @param context/*w w w .ja v  a 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:com.meiste.greg.ptw.QuestionAlarm.java

@Override
protected void onHandleIntent(final Intent intent) {
    alarm_set = false;/* w  w  w . ja  va2  s .c  o  m*/
    final Race race = Race.getInstance(this, intent.getIntExtra(RACE_ID, 0));
    Util.log("Received question alarm for race " + race.getId());

    synchronized (mSync) {
        if (mContainer == null) {
            try {
                mSync.wait();
            } catch (final InterruptedException e) {
            }
        }
    }

    // Only show notification if user wants question reminders
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    if (prefs.getBoolean(EditPreferences.KEY_NOTIFY_QUESTIONS, true)
            && mContainer.getBoolean(GtmHelper.KEY_GAME_ENABLED)) {
        final Intent notificationIntent = new Intent(this, MainActivity.class);
        notificationIntent.putExtra(PTW.INTENT_EXTRA_TAB, 1);
        final PendingIntent pi = PendingIntent.getActivity(this, PI_REQ_CODE, notificationIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);

        int defaults = 0;
        if (prefs.getBoolean(EditPreferences.KEY_NOTIFY_VIBRATE, true))
            defaults |= Notification.DEFAULT_VIBRATE;
        if (prefs.getBoolean(EditPreferences.KEY_NOTIFY_LED, true))
            defaults |= Notification.DEFAULT_LIGHTS;

        final NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_stat_steering_wheel)
                .setTicker(getString(R.string.remind_questions_ticker, race.getName()))
                .setContentTitle(getString(R.string.app_name)).setContentText(race.getName())
                .setContentIntent(pi).setAutoCancel(true).setDefaults(defaults).setSound(Uri
                        .parse(prefs.getString(EditPreferences.KEY_NOTIFY_RINGTONE, PTW.DEFAULT_NOTIFY_SND)));

        getNM(this).notify(R.string.remind_questions_ticker, builder.build());
    } else {
        Util.log("Ignoring question alarm since option is disabled");
    }

    // Remember that user was reminded of this race
    Util.getState(this).edit().putInt(LAST_REMIND, race.getId()).apply();

    // Reset alarm for the next race
    set(this);
    sendBroadcast(new Intent(PTW.INTENT_ACTION_RACE_ALARM));
}

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 {/* w  w w  . java2s .co  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:de.steveliedtke.gcm.example.gcm.GCMIntentService.java

public void displayNotification(final Context context, final String message, final boolean vibrationEnabled,
        final boolean permanentNotification) throws JSONException {
    // TODO rewrite this method: throw notification with message

    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);

    int icon;//from   ww  w . ja  v a  2  s. c om
    CharSequence notificationText;
    final CharSequence contentTitle;
    icon = R.drawable.ic_launcher;
    notificationText = context.getString(R.string.new_message);
    contentTitle = context.getString(R.string.new_message);

    long when = System.currentTimeMillis();

    final NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setSmallIcon(icon);
    builder.setTicker(notificationText);
    builder.setWhen(when);
    if (message != null && message.length() > 0) {
        builder.setStyle(
                new NotificationCompat.BigTextStyle().setSummaryText(notificationText).bigText(message));
    }
    builder.setAutoCancel(true);
    builder.setContentTitle(contentTitle);
    builder.setContentText(notificationText);

    final Notification notification = builder.build();
    if (vibrationEnabled) {
        notification.defaults |= Notification.DEFAULT_VIBRATE;
    }
    mNotificationManager.notify(82917, notification);
}