Example usage for android.app Notification CATEGORY_SERVICE

List of usage examples for android.app Notification CATEGORY_SERVICE

Introduction

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

Prototype

String CATEGORY_SERVICE

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

Click Source Link

Document

Notification category: indication of running background service.

Usage

From source file:com.giovanniterlingen.windesheim.controllers.NotificationController.java

@RequiresApi(api = 26)
public Notification getServiceNotification() {
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ApplicationLoader.applicationContext,
            SERVICE_NOTIFICATION_CHANNEL)
                    .setContentTitle(/* w  ww  . j a  v  a 2s  .  c  o m*/
                            ApplicationLoader.applicationContext.getResources().getString(R.string.app_name))
                    .setContentText(ApplicationLoader.applicationContext.getResources()
                            .getString(R.string.disable_notification_description))
                    .setStyle(new NotificationCompat.BigTextStyle().bigText(ApplicationLoader.applicationContext
                            .getResources().getString(R.string.disable_notification_description)))
                    .setOngoing(true).setSmallIcon(R.drawable.notifybar)
                    .setPriority(NotificationCompat.PRIORITY_MIN).setCategory(Notification.CATEGORY_SERVICE);

    return mBuilder.build();
}

From source file:com.stanleyidesis.quotograph.api.controller.LWQNotificationControllerImpl.java

@Override
public void postSavedWallpaperReadyNotification(Uri filePath, Uri imageUri) {
    final Bitmap savedImage = BitmapFactory.decodeFile(filePath.getPath());
    final Bitmap notificationBitmap = chopToCenterSquare(savedImage);
    savedImage.recycle();/*from ww w  . j  av  a2 s  . c o m*/

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(LWQApplication.get());
    notificationBuilder.setAutoCancel(true);
    notificationBuilder.setCategory(Notification.CATEGORY_SERVICE);
    notificationBuilder.setContentTitle(LWQApplication.get().getString(R.string.notification_title_save_image));
    notificationBuilder
            .setContentText(LWQApplication.get().getString(R.string.notification_content_save_image));
    notificationBuilder.setLights(LWQApplication.get().getResources().getColor(R.color.palette_A100), 500, 500);
    notificationBuilder.setLargeIcon(notificationBitmap);
    notificationBuilder.setOngoing(false);
    notificationBuilder.setShowWhen(false);
    notificationBuilder.setSmallIcon(R.mipmap.ic_stat);
    notificationBuilder.setTicker(LWQApplication.get().getString(R.string.notification_title_save_image));
    notificationBuilder.setWhen(System.currentTimeMillis());
    notificationBuilder.setColor(LWQApplication.get().getResources().getColor(R.color.palette_A100));

    NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
    bigPictureStyle.bigPicture(notificationBitmap);
    bigPictureStyle.bigLargeIcon(notificationBitmap);

    notificationBuilder.setStyle(bigPictureStyle);

    // Set content Intent
    final Intent viewIntent = new Intent(Intent.ACTION_VIEW);
    viewIntent.setDataAndType(imageUri, "image/*");
    final Intent viewChooser = Intent.createChooser(viewIntent,
            LWQApplication.get().getString(R.string.view_using));
    final PendingIntent viewActivity = PendingIntent.getActivity(LWQApplication.get(), uniqueRequestCode++,
            viewChooser, PendingIntent.FLAG_UPDATE_CURRENT);
    notificationBuilder.setContentIntent(viewActivity);

    // Add Share Action
    final Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("image/*");
    shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(filePath.getPath())));
    final Intent shareChooser = Intent.createChooser(shareIntent,
            LWQApplication.get().getString(R.string.share_using));
    final PendingIntent shareActivity = PendingIntent.getActivity(LWQApplication.get(), uniqueRequestCode++,
            shareChooser, PendingIntent.FLAG_UPDATE_CURRENT);
    final NotificationCompat.Action shareAction = new NotificationCompat.Action.Builder(R.mipmap.ic_share_white,
            LWQApplication.get().getString(R.string.share), shareActivity).build();
    notificationBuilder.addAction(shareAction);

    NotificationManager notificationManager = (NotificationManager) LWQApplication.get()
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(savedImage.hashCode(), notificationBuilder.build());
    notificationBitmap.recycle();
}

From source file:com.vuze.android.remote.service.VuzeService.java

private NotificationCompat.Builder getNotificationBuilder() {
    Resources resources = getResources();
    final Intent notificationIntent = new Intent(this, IntentHandler.class);
    final PendingIntent pi = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    String title = resources.getString(R.string.core_noti_title);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.notification_small).setContentTitle(title).setOngoing(true)
            .setCategory(Notification.CATEGORY_SERVICE).setContentIntent(pi);

    if (!isCoreStopping) {
        Intent intentStop = new Intent(this, VuzeService.class);
        intentStop.setAction(INTENT_ACTION_STOP);
        PendingIntent piStop = PendingIntent.getService(this, 0, intentStop, PendingIntent.FLAG_CANCEL_CURRENT);

        builder.addAction(R.drawable.ic_power_settings_new_white_24dp,
                resources.getString(R.string.core_noti_stop_button), piStop);

        AzureusCore core = getCore();/* w  ww.j  a  v  a  2s  .c o m*/
        if (core != null && core.isStarted()) {
            GlobalManager gm = core.getGlobalManager();
            if (gm != null) {
                boolean canPause = gm.canPauseDownloads();
                Intent intentPR = new Intent(this, VuzeService.class);
                intentPR.setAction(canPause ? INTENT_ACTION_PAUSE : INTENT_ACTION_RESUME);
                PendingIntent piPR = PendingIntent.getService(this, 0, intentPR,
                        PendingIntent.FLAG_CANCEL_CURRENT);

                builder.addAction(
                        canPause ? R.drawable.ic_playlist_pause_n : R.drawable.ic_playlist_play_white_n,
                        resources.getString(
                                canPause ? R.string.core_noti_pause_button : R.string.core_noti_resume_button),
                        piPR);
            }
        }

    }

    String subTitle = null;
    if (isCoreStopping || isServiceStopping) {
        int id = restartService ? R.string.core_noti_restarting : R.string.core_noti_stopping;
        subTitle = resources.getString(id);
    } else {
        if (bindToLocalHost) {
            subTitle = resources.getString(bindToLocalHostReasonID);
        } else {
            GlobalManagerStats stats = null;
            AzureusCore core = getCore();
            if (core != null && core.isStarted()) {
                GlobalManager gm = staticCore.getGlobalManager();
                if (gm != null) {
                    stats = gm.getStats();
                }
            }

            if (stats != null) {
                String downSpeed = DisplayFormatters
                        .formatByteCountToKiBEtcPerSec(stats.getDataAndProtocolSendRate());
                String upSpeed = DisplayFormatters
                        .formatByteCountToKiBEtcPerSec(stats.getDataAndProtocolReceiveRate());
                TagManager tagManager = TagManagerFactory.getTagManager();
                Tag tagActive = tagManager.lookupTagByUID(7);// active
                int numActive = tagActive == null ? 0 : tagActive.getTaggedCount();
                subTitle = resources.getQuantityString(R.plurals.core_noti_running, numActive, downSpeed,
                        upSpeed, DisplayFormatters.formatNumber(numActive));
            } else {
                subTitle = resources.getString(R.string.core_noti_starting);
            }

        }
    }
    builder.setContentText(subTitle);

    return builder;
}

From source file:org.proninyaroslav.libretorrent.TorrentTaskService.java

private void makeForegroundNotify() {
    /* For starting main activity */
    // TODO: 05.05.17 
    //        Intent startupIntent = new Intent(getApplicationContext(), MainActivity.class);
    //        startupIntent.setAction(Intent.ACTION_MAIN);
    //        startupIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    //        startupIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    //// w w  w.  j  a  v  a  2s.  co  m
    //        PendingIntent startupPendingIntent =
    //                PendingIntent.getActivity(
    //                        getApplicationContext(),
    //                        0,
    //                        startupIntent,
    //                        PendingIntent.FLAG_UPDATE_CURRENT);
    //
    foregroundNotify = new NotificationCompat.Builder(getApplicationContext())
            .setSmallIcon(R.drawable.ic_power_settings_new_white_24dp)
            //                .setContentIntent(startupPendingIntent)
            .setContentTitle(getString(R.string.app_running_in_the_background))
            .setTicker(getString(R.string.app_running_in_the_background))
            .setContentText((isNetworkOnline ? getString(R.string.network_online)
                    : getString(R.string.network_offline)))
            .setWhen(System.currentTimeMillis());

    /* For shutdown activity and service */
    Intent shutdownIntent = new Intent(getApplicationContext(), NotificationReceiver.class);
    shutdownIntent.setAction(NotificationReceiver.NOTIFY_ACTION_SHUTDOWN_APP);

    PendingIntent shutdownPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, shutdownIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Action shutdownAction = new NotificationCompat.Action.Builder(
            R.drawable.ic_power_settings_new_white_24dp, getString(R.string.shutdown), shutdownPendingIntent)
                    .build();

    foregroundNotify.addAction(shutdownAction);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        foregroundNotify.setCategory(Notification.CATEGORY_SERVICE);
    }

    /* Disallow killing the service process by system */
    startForeground(SERVICE_STARTED_NOTIFICATION_ID, foregroundNotify.build());
}

From source file:org.proninyaroslav.libretorrent.services.TorrentTaskService.java

private void makeForegroundNotify() {
    /* For starting main activity */
    Intent startupIntent = new Intent(getApplicationContext(), MainActivity.class);
    startupIntent.setAction(Intent.ACTION_MAIN);
    startupIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    startupIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);

    PendingIntent startupPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, startupIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    foregroundNotify = new NotificationCompat.Builder(getApplicationContext())
            .setSmallIcon(R.drawable.ic_app_notification).setContentIntent(startupPendingIntent)
            .setContentTitle(getString(R.string.app_running_in_the_background))
            .setTicker(getString(R.string.app_running_in_the_background))
            .setContentText((isNetworkOnline ? getString(R.string.network_online)
                    : getString(R.string.network_offline)))
            .setWhen(System.currentTimeMillis());

    /* For calling add torrent dialog */
    Intent addTorrentIntent = new Intent(getApplicationContext(), NotificationReceiver.class);
    addTorrentIntent.setAction(NotificationReceiver.NOTIFY_ACTION_ADD_TORRENT);

    PendingIntent addTorrentPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0,
            addTorrentIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Action addTorrentAction = new NotificationCompat.Action.Builder(
            R.drawable.ic_add_white_36dp, getString(R.string.add), addTorrentPendingIntent).build();

    foregroundNotify.addAction(addTorrentAction);

    /* For shutdown activity and service */
    Intent shutdownIntent = new Intent(getApplicationContext(), NotificationReceiver.class);
    shutdownIntent.setAction(NotificationReceiver.NOTIFY_ACTION_SHUTDOWN_APP);

    PendingIntent shutdownPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, shutdownIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Action shutdownAction = new NotificationCompat.Action.Builder(
            R.drawable.ic_power_settings_new_white_24dp, getString(R.string.shutdown), shutdownPendingIntent)
                    .build();/* w w w .  ja  v a  2s . c o m*/

    foregroundNotify.addAction(shutdownAction);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        foregroundNotify.setCategory(Notification.CATEGORY_SERVICE);
    }

    /* Disallow killing the service process by system */
    startForeground(SERVICE_STARTED_NOTIFICATION_ID, foregroundNotify.build());
}