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:vrisini.cordova.plugin.schedule.Schedule.java

/**
 * The notification manager for the application.
 *//*w w w.j av a  2 s . c om*/
protected static NotificationManager getNotificationManager() {
    return (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
}

From source file:cc.softwarefactory.lokki.android.androidServices.LocationService.java

private void showArrivalNotification() {
    Intent showIntent = new Intent(this, BuzzActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, showIntent, 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_notify).setContentTitle("GPS Child Location")
            .setContentText(getString(R.string.you_have_arrived)).setAutoCancel(true)
            .setContentIntent(contentIntent);

    ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(42, mBuilder.build());
}

From source file:com.horizondigital.delta.UpdateService.java

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

    Logger.setDebugLogging(getResources().getBoolean(R.bool.debug_output));

    property_version = getProperty(getString(R.string.property_version), "");
    property_device = getProperty(getString(R.string.property_device), "");
    filename_base = String.format(Locale.ENGLISH, getString(R.string.filename_base), property_version);
    path_base = String.format(Locale.ENGLISH, "%s%s%s%s",
            Environment.getExternalStorageDirectory().getAbsolutePath(), File.separator,
            getString(R.string.path_base), File.separator);
    path_flash_after_update = String.format(Locale.ENGLISH, "%s%s%s", path_base, "FlashAfterUpdate",
            File.separator);
    url_base_delta = String.format(Locale.ENGLISH, getString(R.string.url_base_delta), property_device);
    url_base_update = String.format(Locale.ENGLISH, getString(R.string.url_base_update), property_device);
    url_base_full = String.format(Locale.ENGLISH, getString(R.string.url_base_full), property_device);
    apply_signature = getResources().getBoolean(R.bool.apply_signature);

    Logger.d("property_version: %s", property_version);
    Logger.d("property_device: %s", property_device);
    Logger.d("filename_base: %s", filename_base);
    Logger.d("path_base: %s", path_base);
    Logger.d("path_flash_after_update: %s", path_flash_after_update);
    Logger.d("url_base_delta: %s", url_base_delta);
    Logger.d("url_base_update: %s", url_base_update);
    Logger.d("url_base_full: %s", url_base_full);

    config = Config.getInstance(this);

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

    handlerThread = new HandlerThread("CarbonDelta 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.adarshahd.indianrailinfo.donate.PNRTracker.java

private void showNotification(String title, String contentText, ArrayList<String> inboxVal,
        String activityToStart) {
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(mContext);
    notificationBuilder.setSmallIcon(R.drawable.irctc).setContentTitle(title).setContentText(contentText);
    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
    for (String str : inboxVal) {
        inboxStyle.addLine(str);/*from   w ww.j a v a 2  s.com*/
    }
    notificationBuilder.setStyle(inboxStyle);
    notificationBuilder.setOnlyAlertOnce(true);
    if (!activityToStart.equals("")) {
        Intent intent = new Intent(mContext, PNRStat.class);
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);
        // Adds the back stack for the Intent (but not the Intent itself)
        stackBuilder.addParentStack(Presenter.class);
        // Adds the Intent that starts the Activity to the top of the stack
        stackBuilder.addNextIntent(intent);
        PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        notificationBuilder.setContentIntent(pendingIntent);
    }
    NotificationManager notificationManager = (NotificationManager) mContext
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notify = notificationBuilder.build();
    //notify.sound = Uri.parse("content://settings/system/notification_sound");
    notify.sound = Uri
            .parse(mPref.getString("notification_ringtone", "content://settings/system/notification_sound"));
    notify.ledARGB = 0xFF00FF00;
    notify.ledOffMS = 10000;
    notify.ledOnMS = 1500;
    notify.flags |= Notification.FLAG_AUTO_CANCEL;
    notify.flags |= Notification.FLAG_SHOW_LIGHTS;
    if (mPref.getBoolean("notification_vibrate", true)) {
        //Should find out a way to vibrate
        long[] pattern = { 0, 200 };
        notify.vibrate = pattern;
    }
    /*notify.flags = Notification.DEFAULT_ALL;
    notify.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
    notify.flags |= Notification.DEFAULT_SOUND;
    notify.flags |= Notification.DEFAULT_LIGHTS;*/
    notificationManager.notify(0, notify);
}

From source file:dk.microting.softkeyboard.autoupdateapk.AutoUpdateApk.java

private void raise_notification() {
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager nm = (NotificationManager) context.getSystemService(ns);

    String update_file = preferences.getString(UPDATE_FILE, "");
    if (update_file.length() > 0) {
        // raise notification
        Notification notification = new Notification(appIcon, appName + " update", System.currentTimeMillis());
        notification.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_NO_CLEAR;

        CharSequence contentTitle = appName + " update available";
        CharSequence contentText = "Select to install";
        Intent notificationIntent = new Intent(Intent.ACTION_VIEW);
        notificationIntent.setDataAndType(
                Uri.parse("file://" + context.getFilesDir().getAbsolutePath() + "/" + update_file),
                ANDROID_PACKAGE);//from  w  w  w  . j a v  a2s . co  m
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

        notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
        nm.notify(NOTIFICATION_ID, notification);
    } else {
        nm.cancel(NOTIFICATION_ID);
    }
}

From source file:com.webkey.Ipc.java

public void notiyDestroy(Context pContext) {
    if (manager == null)
        manager = (NotificationManager) pContext.getSystemService(Context.NOTIFICATION_SERVICE);
    try {//from w  ww  .  java 2 s  .  co m
        manager.cancel(1);
    } catch (Exception e) {
    }
}

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

@Override
protected void onHandleIntent(final Intent intent) {
    this.nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    final int type = intent.getIntExtra(Constants.EXTRA_TYPE, DownloadService.TYPE_CHECK);
    if (AppContext.DEBUG) {
        Log.d(DownloadService.TAG, "onHandleIntent type=" + type);
    }//from  w  ww  . j  a va2 s .c  o  m
    if (type == DownloadService.TYPE_CHECK) {
        check();
    } else if (type == DownloadService.TYPE_DOWNLOAD) {
        final AppVersionInfo info = intent.getParcelableExtra(Constants.EXTRA_URL);
        log("onHandleIntent TYPE_DOWNLOAD info=" + info);
        if ((info != null) && !TextUtils.isEmpty(info.downloadUrl)) {
            download(info);
        }
    }
}

From source file:com.aniruddhc.acemusic.player.AsyncTasks.AsyncPinSongsTask.java

@Override
protected void onProgressUpdate(Integer... values) {
    int updateCode = values[0];
    switch (updateCode) {
    case 0://from www . ja v  a2 s  . c  o m
        String currentProgressText = getFormattedFileSize((long) currentDownloadedSize) + " of "
                + getFormattedFileSize((long) fileSize);

        PinGMusicSongsService.mBuilder.setTicker(null);
        PinGMusicSongsService.mBuilder.setProgress(fileSize, currentDownloadedSize, false);
        PinGMusicSongsService.mBuilder.setContentText(currentProgressText);
        PinGMusicSongsService.mNotifyManager.notify(PinGMusicSongsService.notificationID,
                PinGMusicSongsService.mBuilder.build());
        break;
    case 1:
        if (i < songTitlesList.size()) {

            //Create the notification that displays the download progress of the song.
            String title = mContext.getResources().getString(R.string.downloading_no_dot) + " "
                    + songTitlesList.get(i);

            PinGMusicSongsService.mNotifyManager = (NotificationManager) mContext
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            PinGMusicSongsService.mBuilder = new NotificationCompat.Builder(mContext);
            PinGMusicSongsService.mBuilder.setContentTitle(title);
            PinGMusicSongsService.mBuilder
                    .setContentText(mContext.getResources().getString(R.string.starting_download));
            PinGMusicSongsService.mBuilder.setSmallIcon(R.drawable.pin_light);
            PinGMusicSongsService.mBuilder.setProgress(0, 0, true);
            PinGMusicSongsService.mNotifyManager.notify(PinGMusicSongsService.notificationID,
                    PinGMusicSongsService.mBuilder.build());
        }
        break;
    case 2:
        Toast.makeText(mContext, R.string.gmusic_app_not_installed_pin, Toast.LENGTH_SHORT).show();
        break;
    }

}

From source file:pt.up.mobile.syncadapter.SigarraSyncAdapter.java

private void syncNotifications(Account account, SyncResult syncResult)
        throws AuthenticationException, IOException {
    final User user = AccountUtils.getUser(getContext(), account.name);
    final String notificationReply = SifeupAPI.getReply(SifeupAPI.getNotificationsUrl(user.getUserCode()),
            account, getContext());//ww  w .  ja va2s  . c  o  m
    final Gson gson = GsonUtils.getGson();
    final Notification[] notifications = gson.fromJson(notificationReply, Notification[].class);
    if (notifications == null) {
        syncResult.stats.numParseExceptions++;
        LogUtils.trackException(getContext(), new RuntimeException(), notificationReply, true);
        return;
    }
    ArrayList<String> fetchedNotCodes = new ArrayList<String>();
    ArrayList<ContentValues> bulkValues = new ArrayList<ContentValues>();
    for (Notification not : notifications) {
        final ContentValues values = new ContentValues();
        values.put(SigarraContract.Notifcations.CONTENT, gson.toJson(not));
        fetchedNotCodes.add(not.getCode());
        if (getContext().getContentResolver().update(SigarraContract.Notifcations.CONTENT_URI, values,
                SigarraContract.Notifcations.UPDATE_NOTIFICATION,
                SigarraContract.Notifcations.getNotificationsSelectionArgs(account.name, not.getCode())) == 0) {
            values.put(SigarraContract.Notifcations.CODE, account.name);
            values.put(SigarraContract.Notifcations.ID_NOTIFICATION, not.getCode());
            values.put(SigarraContract.Notifcations.STATE, SigarraContract.Notifcations.NEW);
            values.put(SigarraContract.Notifcations.CODE, account.name);
            bulkValues.add(values);
        }

    }
    // inserting the values
    if (bulkValues.size() > 0) {
        getContext().getContentResolver().bulkInsert(SigarraContract.Notifcations.CONTENT_URI,
                bulkValues.toArray(new ContentValues[0]));
        // if the account being synced is the current active accout
        // display notification
        if (AccountUtils.getActiveUserName(getContext()).equals(account.name)) {
            final NotificationManager mNotificationManager = (NotificationManager) getContext()
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            NotificationCompat.Builder notBuilder = new NotificationCompat.Builder(getContext());
            notBuilder.setAutoCancel(true).setOnlyAlertOnce(true)
                    .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
            if (bulkValues.size() == 1) {
                final Notification notification = gson.fromJson(
                        bulkValues.get(0).getAsString(SigarraContract.Notifcations.CONTENT),
                        Notification.class);
                Intent notifyIntent = new Intent(getContext(), NotificationsDescActivity.class)
                        .putExtra(NotificationsDescFragment.NOTIFICATION, notification);
                // Creates the PendingIntent
                PendingIntent notifyPendingIntent = PendingIntent.getActivity(getContext(), 0, notifyIntent,
                        PendingIntent.FLAG_UPDATE_CURRENT);

                // Sets the Activity to start in a new, empty task
                notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                notBuilder.setSmallIcon(R.drawable.icon).setTicker(notification.getMessage())
                        .setContentTitle(notification.getSubject()).setContentText(notification.getMessage())
                        .setContentIntent(notifyPendingIntent)
                        .setStyle(new NotificationCompat.BigTextStyle().bigText(notification.getMessage())
                                .setBigContentTitle(notification.getSubject())
                                .setSummaryText(notification.getMessage()));
                mNotificationManager.notify(notification.getCode().hashCode(), notBuilder.build());
            } else {
                final String notTitle = getContext().getString(R.string.new_notifications, bulkValues.size());

                Intent notifyIntent = new Intent(getContext(), NotificationsActivity.class);
                // Sets the Activity to start in a new, empty task
                notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                // Creates the PendingIntent
                PendingIntent notifyPendingIntent = PendingIntent.getActivity(getContext(), 0, notifyIntent,
                        PendingIntent.FLAG_UPDATE_CURRENT);
                NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
                // Sets a title for the Inbox style big view
                inboxStyle.setBigContentTitle(notTitle);
                // Moves events into the big view
                for (ContentValues value : bulkValues) {
                    final Notification notification = gson.fromJson(
                            value.getAsString(SigarraContract.Notifcations.CONTENT), Notification.class);
                    inboxStyle.addLine(notification.getSubject());
                }
                // Moves the big view style object into the notification
                // object.
                notBuilder.setStyle(inboxStyle);
                notBuilder.setSmallIcon(R.drawable.icon).setTicker(notTitle).setContentTitle(notTitle)
                        .setContentText("").setContentIntent(notifyPendingIntent);
                mNotificationManager.notify(NotificationsFragment.class.getName().hashCode(),
                        notBuilder.build());
            }

        }
    }
    final Cursor syncState = getContext().getContentResolver().query(SigarraContract.LastSync.CONTENT_URI,
            SigarraContract.LastSync.COLUMNS, SigarraContract.LastSync.PROFILE,
            SigarraContract.LastSync.getLastSyncSelectionArgs(AccountUtils.getActiveUserName(getContext())),
            null);
    try {
        if (syncState.moveToFirst()) {
            if (syncState.getLong(syncState.getColumnIndex(SigarraContract.LastSync.NOTIFICATIONS)) == 0) {
                // Report that we have checked the notifications
                final ContentValues values = new ContentValues();
                values.put(SigarraContract.LastSync.NOTIFICATIONS, System.currentTimeMillis());
                getContext().getContentResolver().update(SigarraContract.LastSync.CONTENT_URI, values,
                        SigarraContract.LastSync.PROFILE,
                        SigarraContract.LastSync.getLastSyncSelectionArgs(account.name));
            }
        }
    } finally {
        syncState.close();
    }
    ArrayList<String> notToDelete = new ArrayList<String>();
    final Cursor cursor = getContext().getContentResolver().query(SigarraContract.Notifcations.CONTENT_URI,
            new String[] { SigarraContract.Notifcations.ID_NOTIFICATION }, SigarraContract.Notifcations.PROFILE,
            SigarraContract.Notifcations.getNotificationsSelectionArgs(account.name), null);
    try {
        if (cursor.moveToFirst()) {
            do {
                final String code = cursor.getString(0);
                if (!fetchedNotCodes.contains(code))
                    notToDelete.add(code);
            } while (cursor.moveToNext());
        } else {
            // no notifications
            getContext().getContentResolver().notifyChange(SigarraContract.Notifcations.CONTENT_URI, null);
        }
    } finally {
        cursor.close();
    }
    if (notToDelete.size() > 0)
        getContext().getContentResolver().delete(SigarraContract.Notifcations.CONTENT_URI,
                SigarraContract.Notifcations.getNotificationsDelete(notToDelete.toArray(new String[0])),
                SigarraContract.Notifcations.getNotificationsSelectionArgs(account.name,
                        notToDelete.toArray(new String[0])));
    syncResult.stats.numEntries += notifications.length;
}