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:io.github.carlorodriguez.alarmon.AlarmClockService.java

@Override
public void onDestroy() {
    super.onDestroy();
    db.closeConnections();/*from w w  w.jav  a 2 s.  c om*/

    ReceiverNotificationRefresh.stopRefreshing(getApplicationContext());

    final NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    manager.cancel(NOTIFICATION_BAR_ID);

    setSystemAlarmStringOnLockScreen(getApplicationContext(), null);
}

From source file:net.majorkernelpanic.spydroid.SpydroidActivity.java

public void onStart() {
    super.onStart();

    // Lock screen
    wl.acquire();/*from w  w  w.j av  a 2s . c o  m*/

    Intent notificationIntent = new Intent(this, SpydroidActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    Notification notification = builder.setContentIntent(pendingIntent).setWhen(System.currentTimeMillis())
            .setTicker(getText(R.string.notification_title)).setSmallIcon(R.drawable.icon)
            .setContentTitle(getText(R.string.notification_title))
            .setContentText(getText(R.string.notification_content)).build();
    notification.flags |= Notification.FLAG_ONGOING_EVENT;
    ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(0, notification);

}

From source file:eu.chainfire.opendelta.UpdateService.java

@SuppressWarnings("deprecation")
@Override//from w  w  w  . j a  va2  s.  c o m
public void onCreate() {
    super.onCreate();

    config = Config.getInstance(this);

    wakeLock = ((PowerManager) getSystemService(POWER_SERVICE)).newWakeLock(
            config.getKeepScreenOn() ? PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP
                    : PowerManager.PARTIAL_WAKE_LOCK,
            "OpenDelta WakeLock");
    wifiLock = ((WifiManager) getSystemService(WIFI_SERVICE)).createWifiLock(WifiManager.WIFI_MODE_FULL,
            "OpenDelta WifiLock");

    handlerThread = new HandlerThread("OpenDelta Service Thread");
    handlerThread.start();
    handler = new Handler(handlerThread.getLooper());

    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    prefs = PreferenceManager.getDefaultSharedPreferences(this);

    scheduler = new Scheduler(this, this);

    networkState = new NetworkState();
    networkState.start(this, this,
            prefs.getInt(PREF_AUTO_UPDATE_NETWORKS_NAME, PREF_AUTO_UPDATE_NETWORKS_DEFAULT));

    batteryState = new BatteryState();
    batteryState.start(this, this, 50, true);

    screenState = new ScreenState();
    screenState.start(this, this);

    prefs.registerOnSharedPreferenceChangeListener(this);

    autoState();
}

From source file:com.vendsy.bartsy.venue.BartsyApplication.java

private void generateNotification(final String title, final String body, final int count) {
    mHandler.post(new Runnable() {
        public void run() {
            // Get app icon bitmap and scale to fit in notification
            Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
            largeIcon = Bitmap.createScaledBitmap(largeIcon, NOTIFICATION_IMAGE_SIZE, NOTIFICATION_IMAGE_SIZE,
                    true);//from   w  w w  .j a v a  2s .c  o m

            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext())
                    .setLargeIcon(largeIcon).setSmallIcon(R.drawable.ic_launcher).setContentTitle(title)
                    .setContentText(body);

            // Creates an explicit intent for an Activity in your app
            Intent resultIntent = new Intent(getApplicationContext(), 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(getApplicationContext());
            // 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);
            mBuilder.setNumber(count);
            NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                    Context.NOTIFICATION_SERVICE);

            // Play default notification sound
            mBuilder.setDefaults(Notification.DEFAULT_SOUND);
            // mId allows you to update the notification later on.
            mNotificationManager.notify(0, mBuilder.build());
        }
    });
}

From source file:de.appplant.cordova.plugin.notification.NotificationWrapper.java

/**
 * The notification manager for the application.
 *//*from ww w. jav  a  2 s.  c  o  m*/
private NotificationManager getNotificationManager() {
    return (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
}

From source file:me.gpelaez.cordova.plugins.ibeacon.GPIBeacon.java

/**
 * + * Issues a notification to inform the user that server has sent a
 * message. +//from w ww  .  ja va2s  .c  o m
 * @throws JSONException 
 */
@SuppressLint("InlinedApi")
private static void createNotification(Context context, JSONObject json) throws JSONException {
    Bundle extra = new Bundle();
    extra.putString("json", json.toString());

    Intent notificationIntent = new Intent(activity, BeaconNotificationHandler.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.putExtra("beacon", extra);

    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setDefaults(Notification.DEFAULT_ALL).setSmallIcon(context.getApplicationInfo().icon)
            .setWhen(System.currentTimeMillis()).setTicker(json.getString("title"))
            .setContentTitle(json.getString("message")).setContentIntent(contentIntent);

    String message = json.getString("message");
    if (message != null) {
        mBuilder.setContentText(message);
    } else {
        mBuilder.setContentText("<missing message content>");
    }
    mBuilder.addAction(context.getApplicationInfo().icon, json.getString("message"), contentIntent);

    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE))
            .notify((String) getAppName(context), NOTIFICATION_ID, mBuilder.build());
}

From source file:ota.otaupdates.MainActivity.java

private void create_notification(int id, String title, String content) {
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon((android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP
                    ? R.drawable.app_icon_notification
                    : R.drawable.app_icon))
            .setContentTitle(title).setContentText(content);

    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);
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(id, mBuilder.build());
}

From source file:no.firestorm.weathernotificatonservice.WeatherNotificationService.java

/**
 * Make notification and post it to the NotificationManager
 * /*from   w  w  w . j a  va 2s  .com*/
 * @param tickerIcon
 *            Icon shown in notification bar
 * @param contentIcon
 *            Icon shown in notification
 * @param tickerText
 *            Text shown in notification bar
 * @param contentTitle
 *            Title shown in notification
 * @param contentText
 *            Description shown in notification
 * @param contentTime
 *            Time shown in notification
 * @param when2
 */
private void makeNotification(int tickerIcon, int contentIcon, CharSequence tickerText,
        CharSequence contentTitle, CharSequence contentText, CharSequence contentTime, long when2,
        Float temperature) {
    final long when = System.currentTimeMillis();
    // Make notification
    Notification notification = null;

    final Intent notificationIntent = new Intent(WeatherNotificationService.this,
            WeatherNotificationService.class);
    final PendingIntent contentIntent = PendingIntent.getService(WeatherNotificationService.this, 0,
            notificationIntent, 0);

    // Check if Notification.Builder exists (11+)
    if (Build.VERSION.SDK_INT >= 11) {
        // Honeycomb ++
        NotificationBuilder builder = new NotificationBuilder(this);
        builder.setAutoCancel(false);
        builder.setContentTitle(contentTitle);
        builder.setContentText(contentText);
        builder.setTicker(tickerText);
        builder.setWhen(when2);
        builder.setSmallIcon(tickerIcon);
        builder.setOngoing(true);
        builder.setContentIntent(contentIntent);
        if (temperature != null)
            builder.makeContentView(contentTitle, contentText, when2, temperature, tickerIcon);
        notification = builder.getNotification();
    } else {
        // Gingerbread --
        notification = new Notification(tickerIcon, tickerText, when);
        notification.flags = Notification.FLAG_ONGOING_EVENT;

        final RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.weathernotification);
        contentView.setImageViewResource(R.id.icon, contentIcon);
        contentView.setTextViewText(R.id.title, contentTitle);
        contentView.setTextViewText(R.id.title, contentTitle);
        contentView.setTextViewText(R.id.text, contentText);
        contentView.setTextViewText(R.id.time, contentTime);
        notification.contentView = contentView;
    }
    notification.contentIntent = contentIntent;

    // Post notification
    final NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(1, notification);
}

From source file:org.linphone.LinphoneService.java

@Override
public void onCreate() {
    super.onCreate();
    theLinphone = this;

    // Dump some debugging information to the logs
    Hacks.dumpDeviceInformation();/*from  w ww  .ja  v a  2s . com*/
    addCallListner();
    //      tryTogetLastReceive();
    //      tryTogetLastRequest();
    tryKeepOnline();
    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mNotification = new Notification(R.drawable.status_level, "", System.currentTimeMillis());
    mNotification.iconLevel = IC_LEVEL_ORANGE;
    mNotification.flags |= Notification.FLAG_ONGOING_EVENT;
    Intent notificationIntent = new Intent(this, MainViewActivity.class);
    mNofificationContentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    mNotification.setLatestEventInfo(this, NOTIFICATION_TITLE, "", mNofificationContentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mNotification);
    mPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    mAudioManager = ((AudioManager) getSystemService(Context.AUDIO_SERVICE));
    mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    try {
        copyAssetsFromPackage();

        mLinphoneCore = LinphoneCoreFactory.instance().createLinphoneCore(this, LINPHONE_RC,
                LINPHONE_FACTORY_RC, null);

        mLinphoneCore.setPlaybackGain(3);
        mLinphoneCore.setRing(null);

        try {
            initFromConf();
        } catch (LinphoneException e) {
            Log.w(TAG, "no config ready yet");
        }
        TimerTask lTask = new TimerTask() {
            @Override
            public void run() {
                mLinphoneCore.iterate();
            }

        };

        mTimer.scheduleAtFixedRate(lTask, 0, 100);
        IntentFilter lFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
        lFilter.addAction(Intent.ACTION_SCREEN_OFF);
        registerReceiver(mKeepAliveMgrReceiver, lFilter);

    } catch (Exception e) {
        Log.e(TAG, "Cannot start linphone", e);
    }

}