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.androzic.plugin.tracker.SMSReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    String Sender = "";
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    Log.e(TAG, "SMS received");

    Bundle extras = intent.getExtras();/*from   w w w.j  a v  a2s  .co  m*/
    if (extras == null)
        return;

    StringBuilder messageBuilder = new StringBuilder();
    Object[] pdus = (Object[]) extras.get("pdus");
    for (int i = 0; i < pdus.length; i++) {
        SmsMessage msg = SmsMessage.createFromPdu((byte[]) pdus[i]);
        String text = msg.getMessageBody();
        Sender = msg.getDisplayOriginatingAddress();
        Log.w(TAG, "Sender: " + Sender);
        if (text == null)
            continue;
        messageBuilder.append(text);
    }

    String text = messageBuilder.toString();
    boolean flexMode = prefs.getBoolean(context.getString(R.string.pref_tracker_use_flex_mode),
            context.getResources().getBoolean(R.bool.def_flex_mode));

    Log.i(TAG, "SMS: " + text);
    Tracker tracker = new Tracker();
    if (!parseXexunTK102(text, tracker) && !parseJointechJT600(text, tracker)
            && !parseTK102Clone1(text, tracker) && !(parseFlexMode(text, tracker) && flexMode))
        return;

    if (tracker.message != null) {
        tracker.message = tracker.message.trim();
        if ("".equals(tracker.message))
            tracker.message = null;
    }

    tracker.sender = Sender;

    if (!"".equals(tracker.sender)) {
        // Save tracker data
        TrackerDataAccess dataAccess = new TrackerDataAccess(context);
        dataAccess.updateTracker(tracker);

        try {
            Application application = Application.getApplication();
            tracker = dataAccess.getTracker(tracker.sender);//get  latest positon of tracker

            application.sendTrackerOnMap(dataAccess, tracker);
        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        dataAccess.close();

        context.sendBroadcast(new Intent(Application.TRACKER_DATE_RECEIVED_BROADCAST));

        // Show notification
        boolean notifications = prefs.getBoolean(context.getString(R.string.pref_tracker_notifications),
                context.getResources().getBoolean(R.bool.def_notifications));
        if (notifications) {
            Intent i = new Intent("com.androzic.COORDINATES_RECEIVED");
            i.putExtra("title", tracker.message != null ? tracker.message : tracker.name);
            i.putExtra("sender", tracker.name);
            i.putExtra("origin", context.getApplicationContext().getPackageName());
            i.putExtra("lat", tracker.latitude);
            i.putExtra("lon", tracker.longitude);

            String msg = context.getString(R.string.notif_text, tracker.name);
            NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
            builder.setContentTitle(context.getString(R.string.app_name));
            if (tracker.message != null)
                builder.setContentText(tracker.name + ": " + tracker.message);
            else
                builder.setContentText(msg);
            PendingIntent contentIntent = PendingIntent.getBroadcast(context, (int) tracker._id, i,
                    PendingIntent.FLAG_ONE_SHOT);
            builder.setContentIntent(contentIntent);
            builder.setSmallIcon(R.drawable.ic_stat_tracker);
            builder.setTicker(msg);
            builder.setWhen(tracker.time);
            int defaults = Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND;
            boolean vibrate = prefs.getBoolean(context.getString(R.string.pref_tracker_vibrate),
                    context.getResources().getBoolean(R.bool.def_vibrate));
            if (vibrate)
                defaults |= Notification.DEFAULT_VIBRATE;
            builder.setDefaults(defaults);
            builder.setAutoCancel(true);
            Notification notification = builder.build();
            NotificationManager notificationManager = (NotificationManager) context
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.notify((int) tracker._id, notification);
        }

        // Conceal SMS
        boolean concealsms = prefs.getBoolean(context.getString(R.string.pref_tracker_concealsms),
                context.getResources().getBoolean(R.bool.def_concealsms));
        if (concealsms)
            abortBroadcast();
    }
}

From source file:com.arifin.taxi.penumpang.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *//*ww w.  j  av a  2  s. co  m*/
private void generateNotification(Context context, String message) {
    // System.out.println("this is message " + message);
    // System.out.println("NOTIFICATION RECEIVED!!!!!!!!!!!!!!" + 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, MainDrawerActivity.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);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    notification = builder.setContentIntent(intent).setSmallIcon(icon).setTicker(message).setWhen(when)
            .setAutoCancel(true).setContentTitle(title).setContentText(message).build();
    // mNM.notify(NOTIFICATION, notification);

    /*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(0, 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.hoangsong.zumechat.gcm.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 *
 *///from  www.  j ava 2 s  . c  o  m
private void sendNotification(CustomNotification customNotification) {

    String title = getString(R.string.app_name);
    long when = System.currentTimeMillis();

    NotificationCompat.Builder mBuilder = null;
    if (customNotification.getSound().equals("0") && customNotification.getVibrate().equals("0")) {
        mBuilder = new NotificationCompat.Builder(getApplicationContext()).setSmallIcon(R.mipmap.ic_launcher)
                //.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher))
                .setContentTitle(title).setContentText(customNotification.getMessage())// + " " + notificationsList.get(notificationsList.size()-1).getTime())
                //.setNumber(count)
                .setWhen(when).setAutoCancel(true)
        //.setStyle(new NotificationCompat.BigTextStyle().bigText(notificationsList.get(notificationsList.size()-1).getMSG() + " " + notificationsList.get(notificationsList.size()-1).getTime()))
        //.setStyle(bigTextStyle)
        //.setTicker(message)
        ;
    } else if (customNotification.getSound().equals("1")) {
        mBuilder = new NotificationCompat.Builder(getApplicationContext()).setSmallIcon(R.mipmap.ic_launcher)
                //.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher))
                .setContentTitle(title).setContentText(customNotification.getMessage())// + " " + notificationsList.get(notificationsList.size()-1).getTime())
                //.setNumber(count)
                .setWhen(when).setDefaults(Notification.DEFAULT_SOUND).setAutoCancel(true)
        //.setStyle(new NotificationCompat.BigTextStyle().bigText(notificationsList.get(notificationsList.size()-1).getMSG() + " " + notificationsList.get(notificationsList.size()-1).getTime()))
        //.setStyle(bigTextStyle)
        //.setTicker(message)
        ;
    } else if (customNotification.getVibrate().equals("1")) {
        mBuilder = new NotificationCompat.Builder(getApplicationContext()).setSmallIcon(R.mipmap.ic_launcher)
                //.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher))
                .setContentTitle(title).setContentText(customNotification.getMessage())// + " " + notificationsList.get(notificationsList.size()-1).getTime())
                //.setNumber(count)
                .setWhen(when).setDefaults(Notification.DEFAULT_VIBRATE).setAutoCancel(true)
        //.setStyle(new NotificationCompat.BigTextStyle().bigText(notificationsList.get(notificationsList.size()-1).getMSG() + " " + notificationsList.get(notificationsList.size()-1).getTime()))
        //.setStyle(bigTextStyle)
        //.setTicker(message)
        ;
    } else {
        Log.e(Constants.TAG, MyGcmListenerService.class.getName() + " Exception: test all");
        mBuilder = new NotificationCompat.Builder(getApplicationContext()).setSmallIcon(R.mipmap.ic_launcher)
                //.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher))
                .setContentTitle(title).setContentText(customNotification.getMessage())// + " " + notificationsList.get(notificationsList.size()-1).getTime())
                //.setNumber(count)
                .setWhen(when).setDefaults(Notification.DEFAULT_ALL).setAutoCancel(true)
        //.setStyle(new NotificationCompat.BigTextStyle().bigText(notificationsList.get(notificationsList.size()-1).getMSG() + " " + notificationsList.get(notificationsList.size()-1).getTime()))
        //.setStyle(bigTextStyle)
        //.setTicker(message)
        ;
    }

    // Creates an explicit intent for an Activity in your app
    Intent notificationIntent = new Intent(getApplicationContext(), MainActivityPhone.class);
    if (customNotification != null) {
        Bundle bundle = new Bundle();
        bundle.putSerializable("customNotification", customNotification);
        notificationIntent.putExtras(bundle);
    }

    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    // 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(getApplicationContext());
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(MainActivityPhone.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(notificationIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(customNotification.getId(),
            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(customNotification.getId(), mBuilder.build()); //Constants.NOTIFICATION_TYPE_ANNOUNCEMENT, mBuilder.build());
}

From source file:dentex.youtube.downloader.utils.Utils.java

public static void setNotificationDefaults(NotificationCompat.Builder aBuilder) {
    String def = YTD.settings.getString("notification_defaults", "0");
    if (aBuilder != null) {
        if (def.equals("0")) {
            aBuilder.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
        }/*ww  w  .  j  a  v a2s .  c om*/
        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.gsma.rcs.ri.extension.MultiMediaSessionIntentService.java

private void addSessionInvitationNotification(Intent intent, ContactId contact) {
    /* Create pending intent */
    Intent invitation = new Intent(intent);
    String title;//  w w  w .  ja v a  2  s. c  o  m
    if (mMultimediaMessagingSession) {
        invitation.setClass(this, MessagingSessionView.class);
        title = getString(R.string.title_recv_messaging_session);
    } else {
        invitation.setClass(this, StreamingSessionView.class);
        title = getString(R.string.title_recv_streaming_session);
    }
    invitation.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, invitation,
            PendingIntent.FLAG_ONE_SHOT);

    String displayName = RcsContactUtil.getInstance(this).getDisplayName(contact);

    /* Create notification */
    NotificationCompat.Builder notif = new NotificationCompat.Builder(this);
    notif.setContentIntent(contentIntent);
    notif.setSmallIcon(R.drawable.ri_notif_mm_session_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:ca.mudar.snoozy.receiver.PowerConnectionReceiver.java

private void notify(Context context, boolean isConnectedPower, boolean hasVibration, boolean hasSound,
        int notifyCount) {
    final Resources res = context.getResources();

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_notify).setContentTitle(res.getString(R.string.notify_content_title))
            .setAutoCancel(true);//from  w  w w.ja  va2s . com

    if (notifyCount == 1) {
        final int resContentTextSingle = (isConnectedPower ? R.string.notify_content_text_single_on
                : R.string.notify_content_text_single_off);
        mBuilder.setContentText(res.getString(resContentTextSingle));
    } else {
        mBuilder.setNumber(notifyCount).setContentText(res.getString(R.string.notify_content_text_multi));
    }

    if (hasVibration && hasSound) {
        mBuilder.setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND);
    } else if (hasVibration) {
        mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
    } else if (hasSound) {
        mBuilder.setDefaults(Notification.DEFAULT_SOUND);
    }

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(context, MainActivity.class);
    final Bundle extras = new Bundle();
    extras.putBoolean(Const.IntentExtras.INCREMENT_NOTIFY_GROUP, true);
    extras.putBoolean(Const.IntentExtras.RESET_NOTIFY_NUMBER, true);
    resultIntent.putExtras(extras);
    resultIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP
            | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    mBuilder.setContentIntent(
            PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT));

    Intent receiverIntent = new Intent(context, PowerConnectionReceiver.class);
    receiverIntent.setAction(Const.IntentActions.NOTIFY_DELETE);
    PendingIntent deleteIntent = PendingIntent.getBroadcast(context, Const.RequestCodes.RESET_NOTIFY_NUMBER,
            receiverIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setDeleteIntent(deleteIntent);

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

    // NOTIFY_ID allows updates to the notification later on.
    mNotificationManager.notify(Const.NOTIFY_ID, mBuilder.build());
}

From source file:com.yek.keyboard.ChewbaccaUncaughtExceptionHandler.java

public void uncaughtException(Thread thread, Throwable ex) {
    ex.printStackTrace();//from w w  w .j av a2  s .c  om
    Logger.e(TAG, "Caught an unhandled exception!!!", ex);
    boolean ignore = false;

    // https://github.com/AnySoftKeyboard/AnySoftKeyboard/issues/15
    //https://github.com/AnySoftKeyboard/AnySoftKeyboard/issues/433
    String stackTrace = Logger.getStackTrace(ex);
    if (ex instanceof NullPointerException) {
        if (stackTrace.contains(
                "android.inputmethodservice.IInputMethodSessionWrapper.executeMessage(IInputMethodSessionWrapper.java")
                || stackTrace.contains(
                        "android.inputmethodservice.IInputMethodWrapper.executeMessage(IInputMethodWrapper.java")) {
            Logger.w(TAG, "An OS bug has been adverted. Move along, there is nothing to see here.");
            ignore = true;
        }
    } else if (ex instanceof java.util.concurrent.TimeoutException) {
        if (stackTrace.contains(".finalize")) {
            Logger.w(TAG, "An OS bug has been adverted. Move along, there is nothing to see here.");
            ignore = true;
        }
    }

    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(mApp);
        if (ex instanceof OutOfMemoryError
                || (ex.getCause() != null && ex.getCause() instanceof OutOfMemoryError)) {
            logText += "******************************\n" + "****** Memory:" + newline + getMemory();
        }

        if (ex instanceof Resources.NotFoundException) {
            int resourceId = extractResourceIdFromException((Resources.NotFoundException) ex);
            logText += "******************************\n";
            if (resourceId == 0) {
                logText += "Failed to extract resource id from message\n";
            } else {
                String possibleResources = getResourcesNamesWithValue(resourceId);
                if (TextUtils.isEmpty(possibleResources)) {
                    logText += "Could not find matching resources for resource id " + resourceId
                            + ", this may happen if the resource is from an external package.\n";
                } else {
                    logText += "Possible resources for " + resourceId + ":\n";
                }

            }
            logText += "******************************\n";
        }
        logText += "******************************" + newline + "****** Log-Cat:" + newline
                + Logger.getAllLogLines();

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

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

        NotificationCompat.Builder builder = new NotificationCompat.Builder(mApp);
        builder.setSmallIcon(
                Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB ? R.drawable.notification_error_icon
                        : R.drawable.ic_notification_error)
                .setColor(ContextCompat.getColor(mApp, R.color.notification_background_error))
                .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.TESTING_BUILD ? 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(R.id.notification_icon_app_error, builder.build());
    }
    // and sending to the OS
    if (!ignore && mOsDefaultHandler != null) {
        Logger.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:ca.zadrox.dota2esportticker.service.ReminderAlarmService.java

private void notifyDebug() {
    final Resources res = getResources();
    String contentTitle = "Debug Notification";

    String contentText;/*from  w  w w  .ja  va  2  s  . c o  m*/

    long currentTime = TimeUtils.getUTCTime();
    long matchStart = TimeUtils.getUTCTime() + 60000;

    int minutesLeft = (int) (matchStart - currentTime + 59000) / 60000;
    if (minutesLeft < 2 && minutesLeft >= 0) {
        minutesLeft = 1;
    }

    if (minutesLeft < 0) {
        contentText = "debugNotification";
    } else {
        contentText = "debugNotification";
    }

    NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this).setContentTitle(contentTitle)
            .setContentText(contentText).setColor(res.getColor(R.color.theme_primary))
            .setTicker(contentTitle + " is about to start.")
            .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
            .setLights(NOTIFICATION_ARGB_COLOR, NOTIFICATION_LED_ON_MS, NOTIFICATION_LED_OFF_MS)
            .setSmallIcon(R.drawable.ic_notification).setPriority(Notification.PRIORITY_DEFAULT)
            .setAutoCancel(true);

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

    nm.notify(NOTIFICATION_ID, notifBuilder.build());
}

From source file:tw.com.ksmt.cloud.libs.Utils.java

public static void generateNotification(Context context, String title, String message) {
    if (!PrjCfg.NOTIFICATION.equals("true")) {
        return;//from w w w.  jav a 2 s  .c  om
    }

    int icon;
    if (PrjCfg.CUSTOMER.equals(PrjCfg.CUSTOMER_FULLKEY)) {
        icon = R.mipmap.ic_launcher_fullkey;
        title = (title == null) ? context.getString(R.string.app_name_fullkey) : title;
    } else {
        icon = R.mipmap.ic_launcher;
        title = (title == null) ? context.getString(R.string.app_name) : title;
    }

    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder notification = new NotificationCompat.Builder(context).setSmallIcon(icon)
            .setContentText(message).setWhen(when);

    Intent notificationIntent;
    if (message.equals(context.getString(R.string.received_new_announce))) {
        notificationIntent = new Intent(context, AnnounceActivity.class);
    } else {
        notificationIntent = new Intent(context, NotificationActivity.class);
    }

    // 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, 0);
    notification.setContentTitle(title);
    notification.setContentIntent(intent);
    notification.setAutoCancel(true);
    if (PrjCfg.NOTIFICATION_SOUND.equals("true")) {
        notification.setDefaults(Notification.DEFAULT_SOUND);
        if (PrjCfg.NOTIFICATION_VIBRATION.equals("true")) {
            notification.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
        }
    }
    if (PrjCfg.NOTIFICATION_VIBRATION.equals("true")) {
        notification.setDefaults(Notification.DEFAULT_VIBRATE);
        if (PrjCfg.NOTIFICATION_SOUND.equals("true")) {
            notification.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
        }
    }
    notificationManager.notify((int) (Math.random() * 1024 + 1), notification.build());
}

From source file:com.snappy.GCMIntentService.java

@SuppressWarnings("deprecation")
public void triggerNotification(Context context, String message, String fromName, Bundle pushExtras,
        String messageData) {/*from  w  w w  . ja  v a 2  s. c  om*/

    if (fromName != null) {
        final NotificationManager notificationManager = (NotificationManager) getSystemService(
                NOTIFICATION_SERVICE);

        Notification notification = new Notification(R.drawable.icon_notification, message,
                System.currentTimeMillis());

        notification.number = mNotificationCounter + 1;
        mNotificationCounter = mNotificationCounter + 1;

        Intent intent = new Intent(this, SplashScreenActivity.class);
        intent.replaceExtras(pushExtras);
        intent.putExtra(Const.PUSH_INTENT, true);
        intent.setAction(Long.toString(System.currentTimeMillis()));
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_FROM_BACKGROUND
                | Intent.FLAG_ACTIVITY_TASK_ON_HOME);

        PendingIntent pendingIntent = PendingIntent.getActivity(this, notification.number, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        notification.setLatestEventInfo(this, context.getString(R.string.app_name), messageData, pendingIntent);

        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notification.defaults |= Notification.DEFAULT_VIBRATE;
        notification.defaults |= Notification.DEFAULT_SOUND;
        notification.defaults |= Notification.DEFAULT_LIGHTS;
        String notificationId = Double.toString(Math.random());
        notificationManager.notify(notificationId, 0, notification);

    }

    Log.i(LOG_TAG, message);
    Log.i(LOG_TAG, fromName);

}