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:jp.co.ipublishing.esnavi.impl.gcm.GcmIntentService.java

/**
 * Notification??//from   ww  w  .  j  a  va 2s.  co m
 *
 * @param alert 
 */
private void sendNotification(@NonNull Alert alert) {
    final NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    final Intent resultIntent = new Intent(this, MapActivity.class)
            .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    final PendingIntent contentIntent = PendingIntent.getActivity(this, 1, resultIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    final Notification.Builder builder = new Notification.Builder(this).setWhen(System.currentTimeMillis())
            .setContentIntent(contentIntent)
            .setDefaults(
                    Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS)
            .setAutoCancel(true).setTicker(alert.getHeadlineBody()).setContentText(alert.getHeadlineBody());

    onPreSendNotification(builder, alert);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        notificationManager.notify(NOTIFICATION_ID, builder.build());
    } else {
        notificationManager.notify(NOTIFICATION_ID, builder.getNotification());
    }
}

From source file:com.ssm.broadcast.GcmIntentService.java

private void sendNotification(String msg) {

    //msg? ?? ? ?? ? ? ?.

    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

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

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_gcm).setTicker("PeopleTree").setContentTitle("PeopleTree")
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
            //.setWhen(System.currentTimeMillis())
            .setContentText(msg);//from   w  ww  .ja  v  a 2 s.  c o  m

    AudioManager am = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);

    /* Even if the mode is set to "Sound & Vibration" in the phone, 
     * the status code that getRingerMode() returns is RINGER_MODE_NORMAL.
     */
    switch (am.getRingerMode()) {
    case AudioManager.RINGER_MODE_VIBRATE:
        mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
        break;
    case AudioManager.RINGER_MODE_NORMAL:
        mBuilder.setDefaults(Notification.DEFAULT_SOUND);
        break;
    default:
        mBuilder.setDefaults(Notification.DEFAULT_SOUND);
    }

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

From source file:com.rocketsingh.biker.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *///  ww  w  .  j  a  v a2  s .co m
public static void generateNotification(Context context, String message) {
    int icon = R.drawable.ic_launcher;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, message, when);
    String title = context.getString(R.string.app_name);
    Intent notificationIntent = new Intent(context, MapActivity.class);
    notificationIntent.putExtra("fromNotification", "notification");
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    notification.setLatestEventInfo(context, title, message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    System.out.println("notification====>" + message);
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_VIBRATE;
    // notification.defaults |= Notification.DEFAULT_LIGHTS;
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    notification.ledARGB = 0x00000000;
    notification.ledOnMS = 0;
    notification.ledOffMS = 0;
    notificationManager.notify(AndyConstants.NOTIFICATION_ID, notification);
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wakeLock = pm.newWakeLock(
            PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE,
            "WakeLock");
    wakeLock.acquire();
    wakeLock.release();

}

From source file:com.android.marrowbone.anysoftboard.ChewbaccaUncaughtExceptionHandler.java

public void uncaughtException(Thread thread, Throwable ex) {
    Log.e(TAG, "Caught an unhandled exception!!! ", ex);
    boolean ignore = false;

    // https://github.com/AnySoftKeyboard/AnySoftKeyboard/issues/15
    String stackTrace = Log.getStackTrace(ex);
    if (ex instanceof NullPointerException && stackTrace != null && stackTrace.contains(
            "android.inputmethodservice.IInputMethodSessionWrapper.executeMessage(IInputMethodSessionWrapper.java")) {
        // https://github.com/AnySoftKeyboard/AnySoftKeyboard/issues/15
        Log.w(TAG, "An OS bug has been adverted. Move along, there is nothing to see here.");
        ignore = true;/*from w  w w . j  a v a 2 s . c o m*/
    }

    if (!ignore && AnyApplication.getConfig().useChewbaccaNotifications()) {
        String appName = DeveloperUtils.getAppDetails(mApp);

        final CharSequence utcTimeDate = DateFormat.format("kk:mm:ss dd.MM.yyyy", new Date());
        final String newline = DeveloperUtils.NEW_LINE;
        String logText = "Hi. It seems that we have crashed.... Here are some details:" + newline
                + "****** UTC Time: " + utcTimeDate + newline + "****** Application name: " + appName + newline
                + "******************************" + newline + "****** Exception type: "
                + ex.getClass().getName() + newline + "****** Exception message: " + ex.getMessage() + newline
                + "****** Trace trace:" + newline + stackTrace + newline;
        logText += "******************************" + newline + "****** Device information:" + newline
                + DeveloperUtils.getSysInfo();
        if (ex instanceof OutOfMemoryError
                || (ex.getCause() != null && ex.getCause() instanceof OutOfMemoryError)) {
            logText += "******************************\n" + "****** Memory:" + newline + getMemory();
        }
        logText += "******************************" + newline + "****** Log-Cat:" + newline
                + Log.getAllLogLines();

        String crashType = ex.getClass().getSimpleName() + ": " + ex.getMessage();
        Intent notificationIntent = new Intent(mApp, SendBugReportUiActivity.class);
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        notificationIntent.putExtra(SendBugReportUiActivity.EXTRA_KEY_BugReportDetails,
                (Parcelable) new SendBugReportUiActivity.BugReportDetails(ex, logText));

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

        NotificationCompat.Builder builder = new NotificationCompat.Builder(mApp);
        builder.setSmallIcon(R.drawable.notification_error_icon)
                .setTicker(mApp.getText(R.string.ime_crashed_ticker))
                .setContentTitle(mApp.getText(R.string.ime_name))
                .setContentText(mApp.getText(R.string.ime_crashed_sub_text))
                .setSubText(
                        BuildConfig.DEBUG ? crashType : null/*not showing the type of crash in RELEASE mode*/)
                .setWhen(System.currentTimeMillis()).setContentIntent(contentIntent).setAutoCancel(true)
                .setOnlyAlertOnce(true).setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE);

        // notifying
        NotificationManager notificationManager = (NotificationManager) mApp
                .getSystemService(Context.NOTIFICATION_SERVICE);

        notificationManager.notify(1, builder.build());
    }
    // and sending to the OS
    if (!ignore && mOsDefaultHandler != null) {
        Log.i(TAG, "Sending the exception to OS exception handler...");
        mOsDefaultHandler.uncaughtException(thread, ex);
    }

    Thread.yield();
    //halting the process. No need to continue now. I'm a dead duck.
    System.exit(0);
}

From source file:com.lugia.timetable.ReminderService.java

@Override
protected void onHandleIntent(Intent intent) {
    String action = intent.getAction();

    Log.d("ReminderService", "Handle intent : " + action);

    Bundle extra = intent.getExtras();//from  w ww. jav  a2s  .c o m

    String subjectCode = extra.getString(EXTRA_SUBJECT_CODE);
    String header = extra.getString(EXTRA_HEADER);
    String content = extra.getString(EXTRA_CONTENT);

    String boardcastIntent = null;

    Intent notificationIntent = new Intent();
    Uri soundUri = null;

    int notificationId;
    boolean vibrate;

    if (action.equals(ACTION_SCHEDULE_REMINDER)) {
        notificationId = SCHEDULE_NOTIFICATION_ID;

        vibrate = SettingActivity.getBoolean(ReminderService.this, SettingActivity.KEY_SCHEDULE_NOTIFY_VIBRATE,
                false);

        String soundUriStr = SettingActivity.getString(ReminderService.this,
                SettingActivity.KEY_SCHEDULE_NOTIFY_SOUND, "");

        notificationIntent.setClass(ReminderService.this, SubjectDetailActivity.class)
                .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                .putExtra(SubjectDetailActivity.EXTRA_SUBJECT_CODE, subjectCode);

        soundUri = !TextUtils.isEmpty(soundUriStr) ? Uri.parse(soundUriStr) : null;

        boardcastIntent = ReminderReceiver.ACTION_UPDATE_SCHEDULE_REMINDER;
    } else if (action.equals(ACTION_EVENT_REMINDER)) {
        long eventId = intent.getLongExtra(EXTRA_EVENT_ID, -1);

        notificationId = EVENT_NOTIFICATION_ID;

        vibrate = SettingActivity.getBoolean(ReminderService.this, SettingActivity.KEY_EVENT_NOTIFY_VIBRATE,
                false);

        String soundUriStr = SettingActivity.getString(ReminderService.this,
                SettingActivity.KEY_EVENT_NOTIFY_SOUND, "");

        notificationIntent.setClass(ReminderService.this, SubjectDetailActivity.class)
                .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK).setAction(SubjectDetailActivity.ACTION_VIEW_EVENT)
                .putExtra(SubjectDetailActivity.EXTRA_EVENT_ID, eventId)
                .putExtra(SubjectDetailActivity.EXTRA_SUBJECT_CODE, subjectCode);

        soundUri = !TextUtils.isEmpty(soundUriStr) ? Uri.parse(soundUriStr) : null;

        boardcastIntent = ReminderReceiver.ACTION_UPDATE_EVENT_REMINDER;
    } else {
        Log.e(TAG, "Unknow action!");

        return;
    }

    PendingIntent pendingIntent = PendingIntent.getActivity(ReminderService.this, 0, notificationIntent, 0);

    Notification notification = new NotificationCompat.Builder(ReminderService.this)
            .setSmallIcon(R.drawable.ic_notification_reminder).setTicker(header).setContentTitle(header)
            .setContentText(content).setContentIntent(pendingIntent).setAutoCancel(true)
            .setWhen(System.currentTimeMillis()).build();

    // always show the notification light
    notification.defaults |= Notification.DEFAULT_LIGHTS;
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;

    // only vibrate when user enable it
    if (vibrate)
        notification.defaults |= Notification.DEFAULT_VIBRATE;

    // set the notification sound
    notification.sound = soundUri;

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

    manager.notify(notificationId, notification);

    // update the reminder, so it will notify user again on next schedule
    Intent broadcastIntent = new Intent(ReminderService.this, ReminderReceiver.class);
    broadcastIntent.setAction(boardcastIntent);

    sendBroadcast(broadcastIntent);
}

From source file:cn.studyjams.s2.sj0132.bowenyan.mygirlfriend.nononsenseapps.notepad.data.receiver.NotificationHelper.java

/**
 * Displays notifications that have a time occurring in the past (and no
 * location). If no notifications like that exist, will make sure to cancel
 * any notifications showing./*  ww w . jav a  2s  . c om*/
 */
private static void notifyPast(Context context, boolean alertOnce) {
    // Get list of past notifications
    final Calendar now = Calendar.getInstance();

    final List<cn.studyjams.s2.sj0132.bowenyan.mygirlfriend.nononsenseapps.notepad.data.model.sql.Notification> notifications = cn.studyjams.s2.sj0132.bowenyan.mygirlfriend.nononsenseapps.notepad.data.model.sql.Notification
            .getNotificationsWithTime(context, now.getTimeInMillis(), true);

    // Remove duplicates
    makeUnique(context, notifications);

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

    Log.d(TAG, "Number of notifications: " + notifications.size());

    // If empty, cancel
    if (notifications.isEmpty()) {
        // cancelAll permanent notifications here if/when that is
        // implemented. Don't touch others.
        // Dont do this, it clears location
        // notificationManager.cancelAll();
    } else {
        // else, notify
        // Fetch sound and vibrate settings
        final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

        // Always use default lights
        int lightAndVibrate = Notification.DEFAULT_LIGHTS;
        // If vibrate on, use default vibration pattern also
        if (prefs.getBoolean(context.getString(R.string.const_preference_vibrate_key), false))
            lightAndVibrate |= Notification.DEFAULT_VIBRATE;

        // Need to get a new one because the action buttons will duplicate
        // otherwise
        NotificationCompat.Builder builder;

        // if (false)
        // //
        // prefs.getBoolean(context.getString(R.string.key_pref_group_on_lists),
        // // false))
        // {
        // // Group together notes contained in the same list.
        // // Always use listid
        // for (long listId : getRelatedLists(notifications)) {
        // builder = getNotificationBuilder(context,
        // Integer.parseInt(prefs.getString(
        // context.getString(R.string.key_pref_prio),
        // "0")), lightAndVibrate,
        // Uri.parse(prefs.getString(context
        // .getString(R.string.key_pref_ringtone),
        // "DEFAULT_NOTIFICATION_URI")), alertOnce);
        //
        // List<com.nononsenseapps.notepad.data.model.sql.Notification> subList =
        // getSubList(
        // listId, notifications);
        // if (subList.size() == 1) {
        // // Notify as single
        // notifyBigText(context, notificationManager, builder,
        // listId, subList.get(0));
        // }
        // else {
        // notifyInboxStyle(context, notificationManager, builder,
        // listId, subList);
        // }
        // }
        // }
        // else {
        // Notify for each individually
        for (cn.studyjams.s2.sj0132.bowenyan.mygirlfriend.nononsenseapps.notepad.data.model.sql.Notification note : notifications) {
            builder = getNotificationBuilder(context, lightAndVibrate,
                    Uri.parse(prefs.getString(context.getString(R.string.const_preference_ringtone_key),
                            "DEFAULT_NOTIFICATION_URI")),
                    alertOnce);

            notifyBigText(context, notificationManager, builder, note);
        }
        // }
    }
}

From source file:com.gsma.rcs.ri.sharing.geoloc.GeolocSharingIntentService.java

/**
 * Add geoloc share notification//  w  w  w  . ja  v a 2s  .  c  o  m
 * 
 * @param invitation intent
 */
private void addGeolocSharingInvitationNotification(Intent invitation, ContactId contact) {
    /* Create pending intent */
    Intent intent = new Intent(invitation);
    intent.setClass(this, ReceiveGeolocSharing.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    /*
     * If the PendingIntent has the same operation, action, data, categories, components, and
     * flags it will be replaced. Invitation should be notified individually so we use a random
     * generator to provide a unique request code and reuse it for the notification.
     */
    int uniqueId = Utils.getUniqueIdForPendingIntent();
    PendingIntent contentIntent = PendingIntent.getActivity(this, uniqueId, intent,
            PendingIntent.FLAG_ONE_SHOT);

    String displayName = RcsContactUtil.getInstance(this).getDisplayName(contact);
    String title = getString(R.string.title_recv_geoloc_sharing);

    /* Create notification */
    NotificationCompat.Builder notif = new NotificationCompat.Builder(this);
    notif.setContentIntent(contentIntent);
    notif.setSmallIcon(R.drawable.ri_notif_csh_icon);
    notif.setWhen(System.currentTimeMillis());
    notif.setAutoCancel(true);
    notif.setOnlyAlertOnce(true);
    notif.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    notif.setDefaults(Notification.DEFAULT_VIBRATE);
    notif.setContentTitle(title);
    notif.setContentText(getString(R.string.label_from_args, displayName));

    /* Send notification */
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    notificationManager.notify(uniqueId, notif.build());
}

From source file:com.money.manager.ex.notifications.RepeatingTransactionNotifications.java

public void notifyRepeatingTransaction() {
    // create application
    CurrencyUtils currencyUtils = new CurrencyUtils(context);
    // init currencies
    if (!currencyUtils.isInit())
        currencyUtils.init();/*  w  ww  .  j  a  v  a 2  s .c  o  m*/

    // select data
    QueryBillDeposits billDeposits = new QueryBillDeposits(context);
    MoneyManagerOpenHelper databaseHelper = new MoneyManagerOpenHelper(context);

    if (databaseHelper != null) {
        Cursor cursor = databaseHelper.getReadableDatabase().rawQuery(billDeposits.getSource() + " AND "
                + QueryBillDeposits.DAYSLEFT + "<=0 ORDER BY " + QueryBillDeposits.NEXTOCCURRENCEDATE, null);
        if (cursor != null) {
            if (cursor.getCount() > 0) {
                cursor.moveToFirst();
                NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
                while (!cursor.isAfterLast()) {
                    String line = cursor
                            .getString(cursor.getColumnIndex(QueryBillDeposits.USERNEXTOCCURRENCEDATE)) + " "
                            + cursor.getString(cursor.getColumnIndex(QueryBillDeposits.PAYEENAME)) + ": <b>"
                            + currencyUtils.getCurrencyFormatted(
                                    cursor.getInt(cursor.getColumnIndex(QueryBillDeposits.CURRENCYID)),
                                    cursor.getDouble(cursor.getColumnIndex(QueryBillDeposits.AMOUNT)))
                            + "</b>";
                    // add line
                    inboxStyle.addLine(Html.fromHtml("<small>" + line + "</small>"));
                    // move to next row
                    cursor.moveToNext();
                }

                NotificationManager notificationManager = (NotificationManager) context
                        .getSystemService(Context.NOTIFICATION_SERVICE);
                // create pendig intent
                Intent intent = new Intent(context, RepeatingTransactionListActivity.class);
                // set launch from notification // check pin code
                intent.putExtra(RepeatingTransactionListActivity.INTENT_EXTRA_LAUNCH_NOTIFICATION, true);

                PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
                // create notification
                Notification notification = null;
                try {
                    notification = new NotificationCompat.Builder(context).setAutoCancel(true)
                            .setContentIntent(pendingIntent)
                            .setContentTitle(context.getString(R.string.application_name))
                            .setContentText(
                                    context.getString(R.string.notification_repeating_transaction_expired))
                            .setSubText(context
                                    .getString(R.string.notification_click_to_check_repeating_transaction))
                            .setSmallIcon(R.drawable.ic_stat_notification)
                            .setTicker(context.getString(R.string.notification_repeating_transaction_expired))
                            .setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND
                                    | Notification.DEFAULT_LIGHTS)
                            .setNumber(cursor.getCount()).setStyle(inboxStyle).build();
                    // notify 
                    notificationManager.cancel(ID_NOTIFICATION);
                    notificationManager.notify(ID_NOTIFICATION, notification);
                } catch (Exception e) {
                    Log.e(LOGCAT, e.getMessage());
                }
            }
            // close cursor
            cursor.close();
        }
        // close database helper
        //databaseHelper.close();
    }
}

From source file:com.survtapp.gcm.MyGcmListenerService.java

private Notification setBigPictureStyleNotification(String msg, String url, String title) {
    Bitmap remote_picture = null;/*from   ww w  .j ava  2  s  .c  o m*/
    // Create the style object with BigPictureStyle subclass.
    NotificationCompat.BigPictureStyle notiStyle = new NotificationCompat.BigPictureStyle();
    notiStyle.setBigContentTitle(title);
    notiStyle.setSummaryText(msg);
    try {
        remote_picture = getBitmapFromURL(url);
    } catch (Exception e) {
        e.printStackTrace();
    }
    notiStyle.bigPicture(remote_picture);
    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);
    return new NotificationCompat.Builder(this).setSmallIcon(R.drawable.survtapp_notification)
            .setColor(getResources().getColor(R.color.actionbar_color)).setAutoCancel(true)
            .setDefaults(
                    Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND | Notification.FLAG_SHOW_LIGHTS)
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
            .setContentIntent(resultPendingIntent).setContentTitle(title).setContentText(msg)
            .setStyle(notiStyle).build();
}

From source file:pj.rozkladWKD.C2DMReceiver.java

public void showNotification(String ticker, String contentTitle, String contentText, PendingIntent intent,
        int number) {
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);

    int icon = R.drawable.ic_launcher_wkd;
    CharSequence tickerText = ticker;
    long when = System.currentTimeMillis();

    Notification notification = new Notification(icon, tickerText, when);
    Context context = getApplicationContext();
    notification.number = Prefs.getNotificationMessageNextNumber(context);

    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    SharedPreferences prefs = Prefs.get(context);
    if (prefs.getBoolean(Prefs.NOTIFICATION_SOUND, true))
        notification.defaults |= Notification.DEFAULT_SOUND;
    if (prefs.getBoolean(Prefs.NOTIFICATION_VIBRATION, true))
        notification.defaults |= Notification.DEFAULT_VIBRATE;
    notification.defaults |= Notification.DEFAULT_LIGHTS;

    notification.setLatestEventInfo(context, contentTitle, contentText, intent);

    mNotificationManager.notify(NOTIFICATION_ID, notification);

}