Example usage for android.content Context NOTIFICATION_SERVICE

List of usage examples for android.content Context NOTIFICATION_SERVICE

Introduction

In this page you can find the example usage for android.content Context NOTIFICATION_SERVICE.

Prototype

String NOTIFICATION_SERVICE

To view the source code for android.content Context NOTIFICATION_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.app.NotificationManager for informing the user of background events.

Usage

From source file:cat.wuyingren.whatsannoy.utils.SystemUtils.java

public static int createScheduleNotification(Context context, Schedule s) {
    Log.w("UTILS", "createScheduleNotification()");
    ScheduleDataSource dataSource;/*from   w  ww.  j a  v  a  2  s.  c o  m*/

    dataSource = new ScheduleDataSource(context);
    dataSource.open();
    //  Random r = new Random();
    int mId = 0;// r.nextInt();
    //SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    String uri = s.getRingtone(); // prefs.getString("pref_general_sound_key", "");
    Uri ringtone = Uri.parse(uri);
    if (uri == "") { // isEmpty() is not available on API 7
        ringtone = RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_NOTIFICATION);
    }
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle(context.getResources().getString(R.string.app_name))
            .setContentText(context.getResources().getString(R.string.notification));
    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(context, MainActivity.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(MainActivity.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);
    // mId allows you to update the notification later on.
    mBuilder.setSound(ringtone);
    //mBuilder.setWhen(s.getDate());
    mNotificationManager.notify(mId, mBuilder.build());
    s.setIsEnabled(false);
    dataSource.updateSchedule(context, s);
    dataSource.close();
    return mId;
}

From source file:com.cyanogenmod.account.util.CMAccountUtils.java

public static void showNotification(Context context, int id, Notification notification) {
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(id, notification);
}

From source file:com.miz.service.TraktMoviesSyncService.java

private void setupNotification() {
    // Setup up notification
    mBuilder = new NotificationCompat.Builder(getApplicationContext());
    mBuilder.setColor(getResources().getColor(R.color.color_primary));
    mBuilder.setSmallIcon(R.drawable.ic_tv_white_24dp);
    mBuilder.setTicker(getString(R.string.syncMovies));
    mBuilder.setContentTitle(getString(R.string.syncMovies));
    mBuilder.setContentText(getString(R.string.updatingMovieInfo));
    mBuilder.setOngoing(true);/*  w ww .ja  v  a2  s. c o  m*/
    mBuilder.setOnlyAlertOnce(true);

    // Build notification
    Notification updateNotification = mBuilder.build();

    // Show the notification
    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(NOTIFICATION_ID, updateNotification);

    // Tell the system that this is an ongoing notification, so it shouldn't be killed
    startForeground(NOTIFICATION_ID, updateNotification);
}

From source file:com.mjhram.ttaxi.gcm_client.MyGcmListenerService.java

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received./*ww  w  . jav a 2 s  .  com*/
 */
private void sendNotification(String message) {
    Intent intent = new Intent(this, GpsMainActivity.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.circle_green).setContentTitle(getString(R.string.gcmClientGcmMsg))
            .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

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

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

From source file:alaindc.crowdroid.GeofenceTransitionsIntentService.java

/**
 * Posts a notification in the notification bar when a transition is detected.
 * If the user clicks the notification, control goes to the MainActivity.
 *///  w ww.  j  a  va 2 s .co m
private void sendNotification(String nameofsensor) {
    // Create an explicit content Intent that starts the main Activity.
    Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class);

    // Construct a task stack.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    // Add the main Activity to the task stack as the parent.
    stackBuilder.addParentStack(MainActivity.class);

    // Push the content Intent onto the stack.
    stackBuilder.addNextIntent(notificationIntent);

    // Get a PendingIntent containing the entire back stack.
    PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Get a notification builder that's compatible with platform versions >= 4
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

    // Define the notification settings.
    builder.setSmallIcon(R.drawable.icon)
            // In a real app, you may want to use a library like Volley
            // to decode the Bitmap.
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.icon)).setColor(Color.RED)
            .setContentTitle("Geofence Crowdroid").setContentText("Geofence Trigger: " + nameofsensor)
            .setContentIntent(notificationPendingIntent);

    // Dismiss notification once the user touches it.
    builder.setAutoCancel(true);

    // Get an instance of the Notification manager
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    // Issue the notification
    mNotificationManager.notify(0, builder.build());
}

From source file:net.networksaremadeofstring.rhybudd.ZenossPoller.java

@Override
public void onCreate() {
    settings = PreferenceManager.getDefaultSharedPreferences(this);
    //Log.i("ServiceThread","Service Starting");

    BugSenseHandler.initAndStartSession(ZenossPoller.this, "44a76a8c");

    String ns = Context.NOTIFICATION_SERVICE;
    mNM = (NotificationManager) getSystemService(ns);

    PrepAPI(true, false);/*  ww  w. ja v  a2s  . c o  m*/

    eventsHandler = new Handler() {
        public void handleMessage(Message msg) {
            if (msg.what == 1) {
                //onlyAlertOnProd = settings.getBoolean("onlyProductionAlerts", true);
                EventDetails.clear();

                Boolean alertsEnabled = settings.getBoolean("AllowBackgroundService", true);
                if (null != listOfZenossEvents && listOfZenossEvents.size() > 0) {
                    try {
                        EventCount = 0;
                        for (ZenossEvent event : listOfZenossEvents) {
                            if (alertsEnabled && event.isNew()
                                    && ZenossAPI.CheckIfNotify(event.getProdState(), event.getDevice(),
                                            getApplicationContext(),
                                            settings.getBoolean("onlyProductionAlerts", true))) {
                                EventDetails.add(event.getDevice() + ": " + event.getSummary());
                                EventCount++;
                            }
                        }

                        if (EventCount > 0) {
                            Notifications.SendPollNotification(EventCount, EventDetails,
                                    getApplicationContext());
                        }
                    } catch (Exception e) {
                        BugSenseHandler.sendExceptionMessage("ZenossPoller", "eventsHandler", e);
                        e.printStackTrace();
                    }
                } else {
                    //This should never happen but also people should stop using the Poller and move to Rhybudd Push
                }

                if (alertsEnabled) {
                    Notifications.SendStickyNotification(getApplicationContext());
                } else {
                    ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE))
                            .cancel(Notifications.NOTIFICATION_POLLED_STICKY);
                }
            } else if (msg.what == 999) {
                //TODO All manner of bad happened
            }

            EventsRefreshInProgress = false;
        }
    };
}

From source file:com.pinplanet.pintact.GcmIntentService.java

private void sendNotification(String msg, String customData) {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    String type = null;//from www  .j a va  2  s.com
    if (customData != null) {

        customData = customData.replace("\"{", "{");
        customData = customData.replaceFirst(Pattern.quote("}\""), "}");
        Log.d(TAG, "CustomData2: " + customData);
    }
    try {
        JSONObject jsonObject = new JSONObject(customData);
        Log.d(TAG, "jsonObject: " + jsonObject.toString());
        type = jsonObject.getString("type");
        switch (type) {
        case "NEW_CHAT_MESSAGE":
            if (customData != null) {
                sendChatNotification(customData);
            }
            break;
        default:
            sendDefaultNotification();
            break;
        }
    } catch (JSONException e) {
        Log.d(TAG, "JSONException in GcmIntentService: " + e.toString());
        e.printStackTrace();
    }

    //        Intent it = new Intent(this, GroupContactsActivity.class);
    //        //it.putExtra(LeftDeckActivity.SELECTED_OPTIONS, LeftDeckActivity.OPTION_NOTIFY);
    //        // add the following line would show Pintact to the preview page.
    //        // it.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    //        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, it, PendingIntent.FLAG_CANCEL_CURRENT);
    //
    //        NotificationCompat.Builder mBuilder =
    //                new NotificationCompat.Builder(this)
    //                        .setSmallIcon(R.drawable.ic_launcher)
    //                        .setContentTitle("Pintact Update")
    //                        .setStyle(new NotificationCompat.BigTextStyle()
    //                                .bigText(msg))
    //                        .setVibrate(new long[]{1000, 1000, 1000, 1000, 1000})
    //                        .setContentText(msg);
    //
    //        mBuilder.setContentIntent(contentIntent);
    //        mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
    //        SingletonLoginData.getInstance().mNotificationManager = mNotificationManager;
}

From source file:arun.com.chromer.appdetect.AppDetectService.java

private void initChannels() {
    if (Utils.ANDROID_OREO) {
        NotificationChannel channel = new NotificationChannel(CHANNEL_ID, "App Detection Service",
                NotificationManager.IMPORTANCE_MIN);
        channel.setDescription(getString(R.string.app_detection_notification_channel_description));
        NotificationManager notificationManager = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);
        notificationManager.createNotificationChannel(channel);
    }/*from w w w.  j a  v  a2s.co  m*/
}

From source file:com.fanfou.app.opensource.service.DownloadService.java

public static void notifyUpdate(final AppVersionInfo info, final Context context) {
    final String versionInfo = info.versionName;
    final NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    final Notification notification = new Notification(R.drawable.ic_notify_icon,
            "?" + versionInfo, System.currentTimeMillis());

    final PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
            DownloadService.getNewVersionIntent(context, info), 0);
    notification.setLatestEventInfo(context, "?" + versionInfo,
            "", contentIntent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    nm.notify(2, notification);//from  w  w w  .  j  av a 2s. com

}