Example usage for android.app Notification DEFAULT_LIGHTS

List of usage examples for android.app Notification DEFAULT_LIGHTS

Introduction

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

Prototype

int DEFAULT_LIGHTS

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

Click Source Link

Document

Use the default notification lights.

Usage

From source file:im.neon.util.NotificationUtils.java

/**
 * Build an incoming call notification./*from   w w w.  j ava 2 s . co  m*/
 * This notification starts the VectorHomeActivity which is in charge of centralizing the incoming call flow.
 * @param context the context.
 * @param roomName the room name in which the call is pending.
 * @param matrixId the matrix id
 * @param callId the call id.
 * @return the call notification.
 */
public static Notification buildIncomingCallNotification(Context context, String roomName, String matrixId,
        String callId) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setWhen(System.currentTimeMillis());

    builder.setContentTitle(roomName);
    builder.setContentText(context.getString(R.string.incoming_call));
    builder.setSmallIcon(R.drawable.incoming_call_notification_transparent);

    // clear the activity stack to home activity
    Intent intent = new Intent(context, VectorHomeActivity.class);
    intent.setFlags(
            Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(VectorHomeActivity.EXTRA_CALL_SESSION_ID, matrixId);
    intent.putExtra(VectorHomeActivity.EXTRA_CALL_ID, callId);

    // Recreate the back stack
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context).addParentStack(VectorHomeActivity.class)
            .addNextIntent(intent);

    // android 4.3 issue
    // use a generator for the private requestCode.
    // When using 0, the intent is not created/launched when the user taps on the notification.
    //
    PendingIntent pendingIntent = stackBuilder.getPendingIntent((new Random()).nextInt(1000),
            PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(pendingIntent);

    Notification n = builder.build();
    n.flags |= Notification.FLAG_SHOW_LIGHTS;
    n.defaults |= Notification.DEFAULT_LIGHTS;

    return n;
}

From source file:com.etime.TimeAlarmService.java

/**
 * Send a notification to the user with the message 'notificationString'
 * @param notifcationString    The message to notify the user with.
 *//*from w w w  .j av  a2s.  co m*/
private void notification(String notifcationString) {
    CharSequence from = "ETime";
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(), 0);
    Notification notif = new Notification(R.drawable.icon, notifcationString, System.currentTimeMillis());

    notif.flags |= Notification.DEFAULT_LIGHTS;
    notif.defaults |= Notification.DEFAULT_VIBRATE;

    notif.setLatestEventInfo(this, from, notifcationString, contentIntent);
    nm.notify("ETime", APP_ID, notif);
}

From source file:edu.cmu.cylab.starslinger.util.NotificationBroadcastReceiver.java

@SuppressWarnings("deprecation")
public static void doUnseenMessagesNotification(Context ctx, int msgCount, boolean giveNotificationFeedback)
        throws OutOfMemoryError {
    long when = System.currentTimeMillis(); // notification time

    // To create a status bar notification:
    // Get a reference to the NotificationManager:
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager nm = (NotificationManager) ctx.getSystemService(ns);

    String tickerText = ctx.getString(R.string.title_NotifyFileAvailable);

    String contentTitle = String.format(Locale.getDefault(), "%s (%d)", ctx.getString(R.string.app_name),
            msgCount);//  w w  w . j  a  va2 s .c om
    String contentText = String.format(ctx.getString(R.string.label_ClickForNMsgs), msgCount);

    Intent intent = makeMessagesNotificationIntent(ctx);
    intent.setFlags(
            Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    // the next two lines initialize the Notification, using the
    // configurations above
    int visibleMsgCount = msgCount != 1 ? msgCount : 0;
    NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx)//
            .setContentIntent(contentIntent)//
            .setSmallIcon(R.drawable.ic_stat_notify_msg)//
            .setTicker(tickerText)//
            .setWhen(when)//
            .setAutoCancel(true)//
            .setContentTitle(contentTitle)//
            .setContentText(contentText)//
            .setNumber(visibleMsgCount)//
            .setVisibility(NotificationCompat.VISIBILITY_SECRET);

    try {
        builder.setLargeIcon(BitmapFactory.decodeResource(ctx.getResources(), R.drawable.ic_launcher));
    } catch (OutOfMemoryError e) {
        // ignore icon when out of memory
    }

    // set notification alerts based on user preferences
    int defaults = 0;
    if (SafeSlingerPrefs.getNotificationVibrate() && giveNotificationFeedback) {
        defaults |= Notification.DEFAULT_VIBRATE;
    }
    String ringtoneStr = SafeSlingerPrefs.getNotificationRingTone();
    builder.setSound(
            TextUtils.isEmpty(ringtoneStr) || !giveNotificationFeedback ? null : Uri.parse(ringtoneStr));
    defaults |= Notification.DEFAULT_LIGHTS;
    builder.setDefaults(defaults);

    Notification n = builder.build();

    // total messages seen...
    n.number = visibleMsgCount; // API <11
    if (msgCount != 1) {
        // cancel old one since we want to avoid the "1" when updating
        // number
        nm.cancel(HomeActivity.NOTIFY_NEW_MSG_ID);
    }

    // Pass the Notification to the NotificationManager:
    nm.notify(HomeActivity.NOTIFY_NEW_MSG_ID, n);
}

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  ww  w.j  a  v  a  2s .  c om*/
    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.riksof.a320.c2dm.common.C2DMReceiver.java

@Override
protected void onMessage(Context contxt, Intent intent) {

    String unValidatedURL = intent.getStringExtra("payload");
    Log.w("C2DMReceiver", unValidatedURL);

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    int icon = R.drawable.ic_launcher; // icon from resources

    CharSequence tickerText = "You got message !!!"; // ticker-text
    long when = System.currentTimeMillis(); // notification time
    Context context = getApplicationContext(); // application Context

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

    CharSequence contentTitle = "Norification Received !";

    // the next two lines initialize the Notification, using the configurations above
    Notification notification = new Notification(icon, tickerText, when);
    notification.defaults |= Notification.DEFAULT_LIGHTS;
    notification.ledARGB = 0xff00ff00;//w  ww.  ja v  a  2s. co  m
    notification.ledOnMS = 300;
    notification.ledOffMS = 1000;
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    notification.setLatestEventInfo(context, contentTitle, unValidatedURL, contentIntent);
    notificationManager.notify(10001, notification);

    Cache.getInstance().remove(unValidatedURL);
    FileCache fc = new FileCache(context);
    fc.clear();

    Log.w("C2DMReceiver", "finish");
}

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(// ww  w . j  a va  2  s .c  o  m
            Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}

From source file:com.endiansoftware.echo.remotewatch.GcmIntentService.java

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

    Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

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

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_gcm).setContentTitle(msg.get("key1").toString())
            .setContentText(msg.get("key2").toString()).setTicker(msg.get("key1").toString());

    mBuilder.setContentIntent(contentIntent);
    Notification notification = mBuilder.build();

    if (msg.get("collapse_key").toString().equals("Emergency")) {
        notification.flags |= notification.FLAG_INSISTENT | notification.FLAG_AUTO_CANCEL;
        notification.defaults |= Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS;
        notification.vibrate = new long[] { 100L, 100L, 200L, 500L };
    } else {/*from ww  w  . ja va2  s.  c  o m*/
        notification.flags |= notification.FLAG_AUTO_CANCEL;
        notification.defaults |= Notification.DEFAULT_LIGHTS;
        notification.vibrate = new long[] { 100L };
    }
    mNotificationManager.notify(NOTIFICATION_ID, notification);
    PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP,
            "TAG");
    wl.acquire();
}

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);
    }/* w w  w . j a va  2s  .  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.procasy.dubarah_nocker.gcm.MyGcmPushReceiver.java

/**
 * Called when message is received./*from ww  w.j  a  v a 2 s.  co  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.meiste.greg.ptw.RaceAlarm.java

@Override
protected void onHandleIntent(final Intent intent) {
    alarm_set = false;/*from  w w w.ja va 2  s.  c  o 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));
}