Example usage for android.app Notification CATEGORY_SYSTEM

List of usage examples for android.app Notification CATEGORY_SYSTEM

Introduction

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

Prototype

String CATEGORY_SYSTEM

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

Click Source Link

Document

Notification category: system or device status update.

Usage

From source file:com.granita.contacticloudsync.syncadapter.AccountSettings.java

@TargetApi(21)
protected void showNotification(int id, String title, String message) {
    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification.Builder n = new Notification.Builder(context);
    if (Build.VERSION.SDK_INT >= 16) {
        n.setPriority(Notification.PRIORITY_HIGH);
        n.setStyle(new Notification.BigTextStyle().bigText(message));
    }/*from  w w  w .  j av a2 s  .c  o m*/
    if (Build.VERSION.SDK_INT >= 20)
        n.setLocalOnly(true);
    if (Build.VERSION.SDK_INT >= 21)
        n.setCategory(Notification.CATEGORY_SYSTEM);
    n.setSmallIcon(R.drawable.ic_launcher);
    n.setContentTitle(title);
    n.setContentText(message);
    nm.notify(id, Build.VERSION.SDK_INT >= 16 ? n.build() : n.getNotification());
}

From source file:com.android.dragonkeyboardfirmwareupdater.KeyboardFirmwareUpdateService.java

private void showUpdateNotification() {
    Log.d(TAG, "showUpdateNotification: " + getKeyboardString());

    // Intent for triggering the update confirmation page.
    Intent updateConfirmation = new Intent(this, UpdateConfirmationActivity.class);
    updateConfirmation.putExtra(EXTRA_KEYBOARD_NAME, mKeyboardName);
    updateConfirmation.putExtra(EXTRA_KEYBOARD_ADDRESS, mKeyboardAddress);
    updateConfirmation.putExtra(EXTRA_KEYBOARD_FIRMWARE_VERSION, mKeyboardFirmwareVersion);
    updateConfirmation.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    // Intent for postponing update.
    Intent postponeUpdate = new Intent(ACTION_KEYBOARD_UPDATE_POSTPONED);

    // Wrap intents into pending intents for notification use.
    PendingIntent laterIntent = PendingIntent.getBroadcast(this, 0, postponeUpdate,
            PendingIntent.FLAG_UPDATE_CURRENT);
    PendingIntent installIntent = PendingIntent.getActivity(this, 0, updateConfirmation,
            PendingIntent.FLAG_CANCEL_CURRENT);

    // Create a notification object with two buttons (actions)
    mUpdateNotification = new NotificationCompat.Builder(this).setCategory(Notification.CATEGORY_SYSTEM)
            .setContentTitle(getString(R.string.notification_update_title))
            .setContentText(getString(R.string.notification_update_text)).setSmallIcon(R.drawable.ic_keyboard)
            .addAction(new NotificationCompat.Action.Builder(R.drawable.ic_later,
                    getString(R.string.notification_update_later), laterIntent).build())
            .addAction(new NotificationCompat.Action.Builder(R.drawable.ic_install,
                    getString(R.string.notification_update_install), installIntent).build())
            .setAutoCancel(true).setOnlyAlertOnce(true).build();

    // Show the notification via notification manager
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    notificationManager.notify(UPDATE_NOTIFICATION_ID, mUpdateNotification);
}