Example usage for android.app Notification Notification

List of usage examples for android.app Notification Notification

Introduction

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

Prototype

public Notification() 

Source Link

Document

Constructs a Notification object with default values.

Usage

From source file:com.andrew.apollo.NotificationHelper.java

/**
 * Call this to build the {@link Notification}.
 *///from   ww  w.  j a v a 2s . c  om
public void buildNotification(final String albumName, final String artistName, final String trackName,
        final Long albumId, final Bitmap albumArt) {

    // Default notfication layout
    mNotificationTemplate = new RemoteViews(mService.getPackageName(), R.layout.notification_template_base);

    // Set up the content view
    initCollapsedLayout(trackName, artistName, albumArt);

    if (ApolloUtils.hasHoneycomb()) {
        // Notification Builder
        mNotification = new NotificationCompat.Builder(mService).setSmallIcon(R.drawable.stat_notify_music)
                .setContentIntent(getPendingIntent()).setPriority(Notification.PRIORITY_DEFAULT)
                .setContent(mNotificationTemplate).build();
        // Control playback from the notification
        initPlaybackActions();
        if (ApolloUtils.hasJellyBean()) {
            // Expanded notifiction style
            mExpandedView = new RemoteViews(mService.getPackageName(),
                    R.layout.notification_template_expanded_base);
            mNotification.bigContentView = mExpandedView;
            // Control playback from the notification
            initExpandedPlaybackActions();
            // Set up the expanded content view
            initExpandedLayout(trackName, albumName, artistName, albumArt);
        }
        mService.startForeground(APOLLO_MUSIC_SERVICE, mNotification);
    } else {
        // FIXME: I do not understand why this happens, but the
        // NotificationCompat
        // API does not work on Gingerbread. Specifically, {@code
        // #mBuilder.setContent()} won't apply the custom RV in Gingerbread.
        // So,
        // until this is fixed I'll just use the old way.
        mNotification = new Notification();
        mNotification.contentView = mNotificationTemplate;
        mNotification.flags |= Notification.FLAG_ONGOING_EVENT;
        mNotification.icon = R.drawable.stat_notify_music;
        mNotification.contentIntent = getPendingIntent();
        mService.startForeground(APOLLO_MUSIC_SERVICE, mNotification);
    }
}

From source file:step.StepService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    if (Build.VERSION.SDK_INT < 18) {

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.mipmap.step_launcher).setContentTitle("??")
                .setContentText("??");

        Notification notification = mBuilder.build();

        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                new Intent(this, StepCountActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);

        notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
        mBuilder.setContentIntent(contentIntent);
        startForeground(GRAY_SERVICE_ID, notification);//API < 18 ??Notification
    } else {/*from w w w  .ja v  a 2  s . co  m*/
        Intent innerIntent = new Intent(this, GrayInnerService.class);
        startService(innerIntent);
        startForeground(GRAY_SERVICE_ID, new Notification());
    }

    return Service.START_STICKY;
}

From source file:it.uniroma3.android.gpstracklogger.service.GPSLoggingService.java

private void startLogging() {
    Session.setStarted(true);/*w  ww  . j  a  v a 2s  . co  m*/
    Session.getController().setCurrentTrack();
    try {
        startForeground(NOTIFICATION_ID, new Notification());
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    showNotification();
    startGPSManager();
}

From source file:com.ucmap.dingdinghelper.services.TimingService.java

private void increasePriority() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        Notification.Builder mBuilder = new Notification.Builder(this);
        mBuilder.setSmallIcon(R.mipmap.app_logo);
        startForeground(NOTIFICATION_ID, mBuilder.build());
        InnerService.startInnerService(this);
    } else {//ww  w.ja v a 2s . c om
        startForeground(NOTIFICATION_ID, new Notification());
    }
}

From source file:com.futureplatforms.kirin.extensions.localnotifications.LocalNotificationsBackend.java

@SuppressWarnings("deprecation")
public Notification createNotification(Bundle settings, JSONObject obj) {

    // notifications[i] = api.normalizeAPI({
    // 'string': {
    // mandatory: ['title', 'body'],
    // defaults: {'icon':'icon'}
    // },/*from ww  w.j ava2s  . c om*/
    //
    // 'number': {
    // mandatory: ['id', 'timeMillisSince1970'],
    // // the number of ms after which we start prioritising more recent
    // things above you.
    // defaults: {'epsilon': 1000 * 60 * 24 * 365}
    // },
    //
    // 'boolean': {
    // defaults: {
    // 'vibrate': false,
    // 'sound': false
    // }
    // }

    int icon = settings.getInt("notification_icon", -1);
    if (icon == -1) {
        Log.e(C.TAG, "Need a notification_icon resource in the meta-data of LocalNotificationsAlarmReceiver");
        return null;
    }

    Notification n = new Notification();
    n.icon = icon;
    n.flags = Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_AUTO_CANCEL;
    long alarmTime = obj.optLong("timeMillisSince1970");
    long displayTime = obj.optLong("displayTimestamp", alarmTime);
    n.when = displayTime;
    n.tickerText = obj.optString("body");
    n.setLatestEventInfo(mContext, obj.optString("title"), obj.optString("body"), null);

    if (obj.optBoolean("vibrate")) {
        n.defaults |= Notification.DEFAULT_VIBRATE;
    }
    if (obj.optBoolean("sound")) {
        n.defaults |= Notification.DEFAULT_SOUND;
    }

    String uriString = settings.getString("content_uri_prefix");
    if (uriString == null) {
        Log.e(C.TAG, "Need a content_uri_prefix in the meta-data of LocalNotificationsAlarmReceiver");
        return null;
    }

    if (uriString.contains("%d")) {
        uriString = String.format(uriString, obj.optInt("id"));
    }
    Uri uri = Uri.parse(uriString);

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setData(uri);
    n.contentIntent = PendingIntent.getActivity(mContext, 23, intent, PendingIntent.FLAG_ONE_SHOT);
    return n;
}

From source file:org.peercast.core.PeerCastService.java

@Override
public IBinder onBind(Intent i) {
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);

    String iniPath = getFileStreamPath("peercast.ini").getAbsolutePath();
    String resDirPath = getFilesDir().getAbsolutePath();

    boolean showNotify = pref.getBoolean(PeerCastMainActivity.pref_notification, true);

    synchronized (this) {
        if (!isRunning) {
            try {
                assetInstall();//from   w  w w . j  a  v  a 2 s.  c o  m
            } catch (IOException e) {
                Log.e(TAG, "html-dir install failed.");
                return null;
            }

            nativeStart(iniPath, resDirPath);
            startForeground(NOTIFY_ID_FOREGROUND, new Notification());
            if (showNotify) {
                tRefreshNotify = new Timer(false);
                tRefreshNotify.schedule(new TimerTask() {
                    @Override
                    public void run() {
                        if (!isShowNotification) {
                            return;
                        }
                        NotificationManager nm = (NotificationManager) getSystemService(
                                Context.NOTIFICATION_SERVICE);
                        Notification n = createNotification();
                        nm.notify(NOTIFY_ID_FOREGROUND, n);
                    }
                }, intervaltRefreshNotify, intervaltRefreshNotify);
            }
            isRunning = true;
        }
    }
    return serviceMessenger.getBinder();
}

From source file:com.github.play.app.StatusService.java

@SuppressWarnings("deprecation")
private Notification createNotification(final Context context, final Song song, final PendingIntent intent) {
    Notification notification = new Notification();
    notification.icon = drawable.notification;
    notification.flags |= FLAG_ONGOING_EVENT;
    notification.tickerText = getTickerText(song);
    if (SDK_INT >= HONEYCOMB)
        notification.largeIcon = SongArtWrapper.getCachedArt(context, song);
    notification.setLatestEventInfo(context, song.artist, getContentText(song), intent);
    return notification;
}

From source file:net.ccghe.emocha.services.ServerService.java

private void showNotification(String tickertxt, String displayTxt, int max, int progress) {
    NotificationManager notifMgr = (NotificationManager) this.getSystemService(Service.NOTIFICATION_SERVICE);

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

    // construct the Notification object.
    Notification notif = new Notification();

    notif.tickerText = tickertxt;/* w  w  w . j a  va2 s  .  c o m*/
    notif.icon = R.drawable.icon;

    nmView = new RemoteViews(getPackageName(), R.layout.custom_notification_layout);
    nmView.setProgressBar(R.id.progressbar, max, progress, false);
    nmView.setTextViewText(R.id.TextView01, displayTxt);

    notif.contentView = nmView;

    notif.contentIntent = contentIntent;
    notifMgr.notify(R.layout.custom_notification_layout, notif);
}

From source file:com.perm.DoomPlay.PlayingService.java

private Notification createNotification() {

    Intent intentActivity;//from w ww  .jav  a  2 s .c om

    if (SettingActivity.getPreferences(SettingActivity.keyOnClickNotif)) {
        intentActivity = new Intent(FullPlaybackActivity.actionReturnFull);
        intentActivity.setClass(this, FullPlaybackActivity.class);
        intentActivity.putExtra(FileSystemActivity.keyMusic, audios);
    } else {
        intentActivity = FullPlaybackActivity.getReturnSmallIntent(this, audios);
    }
    intentActivity.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    Notification notification = new Notification();
    notification.contentView = getNotifViews(R.layout.notif);
    notification.flags |= Notification.FLAG_FOREGROUND_SERVICE;
    notification.contentIntent = PendingIntent.getActivity(this, 0, intentActivity,
            PendingIntent.FLAG_UPDATE_CURRENT);
    notification.icon = isPlaying ? R.drawable.status_icon_pause : R.drawable.status_icon_play;

    return notification;
}

From source file:com.freshplanet.nativeExtensions.C2DMBroadcastReceiver.java

private void extractColors(Context context) {
    if (notification_text_color != null)
        return;/*w  ww . j  a  v a  2 s  . c  om*/

    try {
        Notification ntf = new Notification();
        ntf.setLatestEventInfo(context, COLOR_SEARCH_RECURSE_TIP, "Utest", null);
        LinearLayout group = new LinearLayout(context);
        ViewGroup event = (ViewGroup) ntf.contentView.apply(context, group);
        recurseGroup(context, event);
        group.removeAllViews();
    } catch (Exception e) {
        notification_text_color = android.R.color.black;
    }
}