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:zemin.notification.NotificationRemoteCallback.java

/**
 * Create a new {@link android.app.Notification} object.
 *
 * @param remote/*w w  w. java  2s  .c o m*/
 * @param entry
 * @param layoutId
 * @return Notification
 */
public Notification makeStatusBarNotification(NotificationRemote remote, NotificationEntry entry,
        int layoutId) {

    final int entryId = entry.ID;
    final CharSequence title = entry.title;
    final CharSequence text = entry.text;
    CharSequence tickerText = entry.tickerText;

    NotificationCompat.Builder builder = new NotificationCompat.Builder(remote.getContext());
    if (entry.smallIconRes > 0) {
        builder.setSmallIcon(entry.smallIconRes);
    } else {
        Log.w(TAG, "***************** small icon not set.");
    }

    if (tickerText == null) {
        Log.w(TAG, "***************** tickerText not set.");
        tickerText = title + ": " + text;
    }

    if (entry.largeIconBitmap != null) {
        builder.setLargeIcon(entry.largeIconBitmap);
    }

    builder.setTicker(tickerText);
    builder.setContentTitle(title);
    builder.setContentText(text);
    builder.setShowWhen(entry.showWhen);

    if (entry.showWhen && entry.whenLong > 0) {
        builder.setWhen(entry.whenLong);
    }

    PendingIntent deleteIntent = remote.getDeleteIntent(entryId);
    builder.setDeleteIntent(deleteIntent);

    PendingIntent contentIntent = remote.getContentIntent(entryId, entry.activityClass, entry.extra,
            entry.autoCancel);
    builder.setContentIntent(contentIntent);
    builder.setAutoCancel(entry.autoCancel);

    builder.setOngoing(entry.ongoing);

    if (entry.useSystemEffect) {
        int defaults = 0;
        if (entry.playRingtone) {
            if (entry.ringtoneUri != null) {
                builder.setSound(entry.ringtoneUri);
            } else {
                defaults |= Notification.DEFAULT_SOUND;
            }
        }

        if (entry.useVibration) {
            if (entry.vibratePattern != null) {
                builder.setVibrate(entry.vibratePattern);
            } else {
                defaults |= Notification.DEFAULT_VIBRATE;
            }
        }

        if (defaults != 0) {
            builder.setDefaults(defaults);
        }
    }

    return builder.build();
}

From source file:org.enbyted.android.zseinfo.view.NotificationManager.java

public static void notifyNewReplacements() {
    if (builderNewReplacements == null) {
        builderNewReplacements = new NotificationCompat.Builder(getContext());
        builderNewReplacements.setSmallIcon(R.drawable.ic_launcher);
    }//  w  w w  .ja v  a  2 s . com

    builderNewReplacements.setContentTitle("Nowe zastpstwa!");
    builderNewReplacements.setContentText("Zastpstwa na jutro s ju dostpne!");
    builderNewReplacements.setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND);

    Intent resultIntent = new Intent(getContext(), MainActivity.class);
    resultIntent.putExtra("tab", "TAB_REPLACEMENTS");
    resultIntent.putExtra("my_class", false);
    resultIntent.putExtra("TYPE", ID_NEW_REPLACEMENT);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(getContext());

    stackBuilder.addNextIntent(resultIntent);

    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    builderNewReplacements.setContentIntent(resultPendingIntent);

    getManager().notify(ID_NEW_REPLACEMENT, builderNewReplacements.build());
}

From source file:de.nitri.aptimob.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*  ww w.  j a v  a 2  s  .co  m*/
 */
private void sendNotification(String message) {

    /*  Intent intent = new Intent(this, MainActivity.class);
      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
      PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 */
    /* Request code *//*, intent,
                      PendingIntent.FLAG_ONE_SHOT);
                              
                      Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
                      NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                      .setSmallIcon(R.drawable.ic_stat_ic_notification)
                      .setContentTitle("GCM Message")
                      .setContentText(message)
                      .setAutoCancel(true)
                      .setSound(defaultSoundUri)
                      .setContentIntent(pendingIntent);
                              
                      NotificationManager notificationManager =
                      (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                              
                      notificationManager.notify(0 *//* ID of notification *//*, notificationBuilder.build());*/

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.icon_notification_bubble).setContentTitle(getString(R.string.app_name))
            .setContentText(message).setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
            .setDefaults(Notification.DEFAULT_VIBRATE).setTicker(message);
    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(this, AptiMob.class);
    resultIntent.putExtra("newMessage", true);

    // The stack builder object will contain an artificial back stack for
    // the
    // started Activity.
    // This ensures that navigating backward from the Activity leads out of
    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(AptiMobMain.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(0, mBuilder.build());
}

From source file:org.rti.rcd.ict.lgug.C2DMReceiver.java

@Override
protected void onMessage(Context context, Intent intent) {
    //String accountName = intent.getExtras().getString(Config.C2DM_ACCOUNT_EXTRA);
    String accountName = intent.getStringExtra("account");
    String message = intent.getExtras().getString(Config.C2DM_MESSAGE_EXTRA);
    Log.d(TAG, "Messaging request received for account " + accountName);
    //        CoconutActivity c = CoconutActivity.getRef();
    //        c.displayMessage( message );
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
    int icon = R.drawable.icon;
    CharSequence tickerText = "Olutindo";
    long when = System.currentTimeMillis();

    Notification notification = new Notification(icon, tickerText, when);
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_VIBRATE;

    notification.flags = Notification.FLAG_AUTO_CANCEL;

    notification.defaults |= Notification.DEFAULT_LIGHTS;
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    notification.ledARGB = 0xff00ff00;/*from  w w  w . j  ava2  s. co m*/
    notification.ledOnMS = 300;
    notification.ledOffMS = 1000;

    //Context context = getApplicationContext();
    Log.d(TAG, "Triggering once_off replication upon receipt of notification: " + message);
    Properties properties = new Properties();
    try {
        InputStream rawResource = getResources().openRawResource(R.raw.coconut);
        properties.load(rawResource);
        System.out.println("The properties are now loaded");
        System.out.println("properties: " + properties);
    } catch (Resources.NotFoundException e) {
        System.err.println("Did not find raw resource: " + e);
    } catch (IOException e) {
        System.err.println("Failed to open microlog property file");
    }
    String localDb = "http://localhost:" + properties.getProperty("local_couch_app_port") + "/"
            + properties.getProperty("app_db");
    Log.d(TAG, "localDb: " + localDb);

    //       String localReplicationDbUrl = "http://localhost:" + properties.getProperty("local_couch_app_port") +"/_replicate";
    //       String replicationMasterUrl = "http://" + properties.getProperty("master_server") + "/coconut";
    //       String replicationDataFromMaster = "{\"_id\": \"once_off_from_master\",\"target\":\"" + localDb + "\",\"source\":\"" + replicationMasterUrl + "\"}";
    //       String replicationDataToMaster = "{\"_id\": \"once_off_to_master\",\"target\":\"" + replicationMasterUrl + "\",\"source\":\"" + localDb + "\"}";
    //    
    //       try {
    //         HTTPRequest.post(localReplicationDbUrl, replicationDataFromMaster);
    //      } catch (JSONException e) {
    //         Log.d(TAG, "Problem installing replication target FromMaster. replicationMasterUrl: " + replicationMasterUrl + " Error:" + e.getMessage());
    //         e.printStackTrace();
    //      } catch (ConnectException e) {
    //         Log.d(TAG, "Unable to connect to replicationMasterUrl: " + replicationMasterUrl + " Error:" + e.getMessage());
    //      }
    //       try {
    //          HTTPRequest.post(localReplicationDbUrl, replicationDataToMaster);
    //       } catch (JSONException e) {
    //          Log.d(TAG, "Problem installing replication target ToMaster. replicationMasterUrl: " + replicationMasterUrl + " Error:" + e.getMessage());
    //          e.printStackTrace();
    //       } catch (ConnectException e) {
    //          Log.d(TAG, "Unable to connect to replicationMasterUrl: " + replicationMasterUrl + " Error:" + e.getMessage());
    //      }
    CharSequence contentTitle = "New Olutindo Message";
    //CharSequence contentText = "Hello World!";
    Intent notificationIntent = new Intent(this, CoconutActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    notification.setLatestEventInfo(context, contentTitle, message, contentIntent);

    mNotificationManager.notify(HELLO_ID, notification);
}

From source file:com.josetomastocino.siteupclient.app.GcmIntentService.java

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

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

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_siteup).setContentTitle("SiteUp Notification")
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
            .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE).setContentText(msg);

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

From source file:org.sirimangalo.meditationplus.ReceiverAlarm.java

@Override
public void onReceive(Context context, Intent pIntent) {
    Log.v(TAG, "ALARM: received alarm");

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

    if (player != null) {
        Log.v(TAG, "Releasing media player...");
        try {// www .j  a v a 2s .c  om
            player.release();
            player = null;
        } catch (Exception e) {
            e.printStackTrace();
            player = null;
        } finally {
            // do nothing
        }
    }

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    if (!prefs.getBoolean("set_alarm", false))
        return;

    player = new MediaPlayer();

    int setTime = pIntent.getIntExtra("period_time", 0);
    String medType = pIntent.getStringExtra("type");

    String title = context.getString(R.string.alarm_title);
    String desc = String.format(context.getString(R.string.alarm_desc), medType, setTime);

    Log.v(TAG, "Notification: " + desc);

    // Load the settings
    boolean led = prefs.getBoolean("alarm_led", true);
    boolean vibrate = prefs.getBoolean("alarm_vibrate", true);
    String notificationUri = prefs.getString("notification_uri",
            "android.resource://org.sirimangalo.meditationplus/" + R.raw.bell);

    Log.v(TAG, "notification uri: " + notificationUri);

    if (notificationUri.equals("system"))
        notificationUri = prefs.getString("SystemUri", "");
    else if (notificationUri.equals("file"))
        notificationUri = prefs.getString("FileUri", "");
    else if (notificationUri.equals("tts")) {
        notificationUri = "";
        final String ttsString = prefs.getString("tts_string", desc);
        Intent ttsIntent = new Intent(context, ServiceTTS.class);
        ttsIntent.putExtra("spoken_text", ttsString);
        context.startService(ttsIntent);
    }

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context.getApplicationContext())
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle(title).setContentText(desc);

    Uri uri = Uri.parse(notificationUri);
    mBuilder.setSound(uri);

    // Vibrate
    if (vibrate) {
        mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
    }
    // Have a light
    if (led) {

        String colorString = prefs.getString("alarm_led_color", "#FFFFFF");

        int color = 0xffffffff;

        try {
            color = Color.parseColor(colorString);
        } catch (Exception e) {

        }

        mBuilder.setLights(color, 300, 1000);
    }

    mBuilder.setAutoCancel(true);

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(context, ActivityMain.class);

    // The stack builder object will contain an artificial back stack for the
    // started Activity.
    // This ensures that navigating backward from the Activity leads out of
    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(ActivityMain.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    mNotificationManager.notify(0, mBuilder.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);
    }/*from   w w  w  . j  a v a 2 s .c o m*/
    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:com.herokuapp.pushdemoandroid.GcmIntentService.java

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

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

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_gcm).setContentTitle("GCM Notification")
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg);

    mBuilder.setContentIntent(contentIntent);
    mBuilder.setDefaults(//from   w w  w  .j  a  v  a 2  s .  c o  m
            Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}

From source file:com.NotifyMe.GcmIntentService.java

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

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

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_gcm).setContentTitle("NotifyMe").setAutoCancel(true)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg)
            .setDefaults(Notification.DEFAULT_VIBRATE).setOnlyAlertOnce(true);

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

From source file:com.example.mego.adas.accidents.fcm.ADASFirebaseMessageService.java

/**
 * Create and show a accident notification containing the received FCM message
 *
 * @param longitude     accident longitude
 * @param latitude      accident latitude
 * @param accidentState accident state true if the accident update location , false if new accident
 * @param title         the accident title
 *///from  www. jav a 2 s. c  o  m

private void sendAccidentNotification(Context context, double longitude, double latitude, boolean accidentState,
        String title) {

    //Check if new accident or updated one
    String notificationText = "An accident occurred at longitude: " + longitude + " and latitude: " + latitude;
    if (accidentState) {
        notificationText = "An accident location changed to longitude: " + longitude + " and latitude: "
                + latitude;
    }

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
            .setColor(ContextCompat.getColor(context, R.color.colorPrimary)).setSmallIcon(R.mipmap.ic_launcher)
            .setLargeIcon(NotificationUtils.largeIcon(context)).setContentTitle(title)
            .setContentText(notificationText)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(notificationText))
            .setDefaults(Notification.DEFAULT_VIBRATE).setDefaults(Notification.DEFAULT_SOUND)
            .setContentIntent(contentIntent(context, longitude, latitude)).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_FCM_NOTIFICATION_ID, notificationBuilder.build());
}