Search in sources :

Example 16 with Builder

use of android.support.v4.app.NotificationCompat.Builder in project Android-Developers-Samples by johnjohndoe.

the class MainActivity method sendNotification.

/**
     * Send a sample notification using the NotificationCompat API.
     */
public void sendNotification(View view) {
    // BEGIN_INCLUDE(build_action)
    /** Create an intent that will be fired when the user clicks the notification.
         * The intent needs to be packaged into a {@link android.app.PendingIntent} so that the
         * notification service can fire it on our behalf.
         */
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://developer.android.com/reference/android/app/Notification.html"));
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
    // END_INCLUDE(build_action)
    // BEGIN_INCLUDE (build_notification)
    /**
         * Use NotificationCompat.Builder to set up our notification.
         */
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    /** Set the icon that will appear in the notification bar. This icon also appears
         * in the lower right hand corner of the notification itself.
         *
         * Important note: although you can use any drawable as the small icon, Android
         * design guidelines state that the icon should be simple and monochrome. Full-color
         * bitmaps or busy images don't render well on smaller screens and can end up
         * confusing the user.
         */
    builder.setSmallIcon(R.drawable.ic_stat_notification);
    // Set the intent that will fire when the user taps the notification.
    builder.setContentIntent(pendingIntent);
    // Set the notification to auto-cancel. This means that the notification will disappear
    // after the user taps it, rather than remaining until it's explicitly dismissed.
    builder.setAutoCancel(true);
    /**
         *Build the notification's appearance.
         * Set the large icon, which appears on the left of the notification. In this
         * sample we'll set the large icon to be the same as our app icon. The app icon is a
         * reasonable default if you don't have anything more compelling to use as an icon.
         */
    builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));
    /**
         * Set the text of the notification. This sample sets the three most commononly used
         * text areas:
         * 1. The content title, which appears in large type at the top of the notification
         * 2. The content text, which appears in smaller text below the title
         * 3. The subtext, which appears under the text on newer devices. Devices running
         *    versions of Android prior to 4.2 will ignore this field, so don't use it for
         *    anything vital!
         */
    builder.setContentTitle("BasicNotifications Sample");
    builder.setContentText("Time to learn about notifications!");
    builder.setSubText("Tap to view documentation about notifications.");
    // END_INCLUDE (build_notification)
    // BEGIN_INCLUDE(send_notification)
    /**
         * Send the notification. This will immediately display the notification icon in the
         * notification bar.
         */
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFICATION_ID, builder.build());
// END_INCLUDE(send_notification)
}
Also used : NotificationManager(android.app.NotificationManager) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 17 with Builder

use of android.support.v4.app.NotificationCompat.Builder in project Klyph by jonathangerbaud.

the class KlyphNotification method setInboxStyle.

public static void setInboxStyle(Builder builder, String title, List<String> lines) {
    builder.setNumber(lines.size());
    InboxStyle inboxStyle = new InboxStyle();
    inboxStyle.setBigContentTitle(title);
    for (String line : lines) {
        inboxStyle.addLine(line);
    }
    builder.setStyle(inboxStyle);
}
Also used : InboxStyle(android.support.v4.app.NotificationCompat.InboxStyle)

Example 18 with Builder

use of android.support.v4.app.NotificationCompat.Builder in project Klyph by jonathangerbaud.

the class KlyphNotification method getBuilder.

public static Builder getBuilder(Context context, boolean alert) {
    Builder builder = new Builder(context).setSmallIcon(R.drawable.ic_notification).setAutoCancel(true);
    if (alert == true) {
        int defaults = 0;
        if (KlyphPreferences.getNotificationRingtone() != null && KlyphPreferences.getNotificationRingtone().equals("default")) {
            defaults |= android.app.Notification.DEFAULT_SOUND;
        } else if (KlyphPreferences.getNotificationRingtoneUri() == null) {
            builder.setSound(null);
        } else {
            builder.setSound(Uri.parse(KlyphPreferences.getNotificationRingtoneUri()));
        }
        if (KlyphPreferences.isNotificationVibrationEnabled() == true)
            defaults |= android.app.Notification.DEFAULT_VIBRATE;
        defaults |= android.app.Notification.DEFAULT_LIGHTS;
        builder.setDefaults(defaults);
        builder.setOnlyAlertOnce(true);
    }
    return builder;
}
Also used : TaskStackBuilder(android.support.v4.app.TaskStackBuilder) Builder(android.support.v4.app.NotificationCompat.Builder)

Example 19 with Builder

use of android.support.v4.app.NotificationCompat.Builder in project Klyph by jonathangerbaud.

the class KlyphNotification method sendNotification.

public static void sendNotification(Context context, Builder builder, Notification notification) {
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    Intent resultIntent = null;
    final String id = notification.getObject_id();
    final String name = notification.getObject_name();
    final String type = notification.getObject_type();
    if (type.equals(Notification.TYPE_FRIEND) || type.equals(Notification.TYPE_POKE) || type.equals(Notification.TYPE_USER)) {
        resultIntent = Klyph.getIntentForParams(context, id, name, Notification.TYPE_FRIEND);
        stackBuilder.addParentStack(UserActivity.class);
    } else if (type.equals(Notification.TYPE_EVENT)) {
        resultIntent = Klyph.getIntentForParams(context, id, name, type);
        stackBuilder.addParentStack(EventActivity.class);
    } else if (type.equals(Notification.TYPE_PAGE)) {
        resultIntent = Klyph.getIntentForParams(context, id, name, type);
        stackBuilder.addParentStack(PageActivity.class);
    } else if (type.equals(Notification.TYPE_GROUP)) {
        if (notification.getGroup().getGid().length() == 0) {
            // That is not a group but a post in a group
            resultIntent = new Intent(context, StreamActivity.class);
            resultIntent.putExtra(KlyphBundleExtras.STREAM_GROUP, true);
            resultIntent.putExtra(KlyphBundleExtras.STREAM_ID, id);
            stackBuilder.addParentStack(StreamActivity.class);
        } else {
            resultIntent = Klyph.getIntentForParams(context, id, name, type);
            stackBuilder.addParentStack(GroupActivity.class);
        }
    } else if (type.equals(Notification.TYPE_PHOTO)) {
        resultIntent = new Intent(context, ImageActivity.class);
        resultIntent.putExtra(KlyphBundleExtras.PHOTO_ID, id);
        stackBuilder.addParentStack(ImageActivity.class);
    } else if (type.equals(Notification.TYPE_ALBUM)) {
        resultIntent = new Intent(context, AlbumPhotosActivity.class);
        resultIntent.putExtra(KlyphBundleExtras.ALBUM_ID, id);
        resultIntent.putExtra(KlyphBundleExtras.ALBUM_NAME, name);
    } else if (type.equals(Notification.TYPE_APP_REQUEST)) {
        resultIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(notification.getHref()));
    } else if (type.equals(Notification.TYPE_VIDEO)) {
        resultIntent = new Intent(context, MainActivity.class);
    // ???
    // resultIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(notification.getHref()));
    } else {
        // Stream
        resultIntent = new Intent(context, StreamActivity.class);
        resultIntent.putExtra(KlyphBundleExtras.STREAM_ID, id);
        stackBuilder.addParentStack(StreamActivity.class);
    }
    resultIntent.putExtra(KlyphBundleExtras.SET_NOTIFICATION_AS_READ, true);
    resultIntent.putExtra(KlyphBundleExtras.NOTIFICATION_ID, notification.getNotification_id());
    // Adds the Intent to the top of the stack
    stackBuilder.addNextIntentWithParentStack(resultIntent);
    int intentCode = (int) Math.round(Math.random() * 1000000);
    // Gets a PendingIntent containing the entire back stack
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(intentCode, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(resultPendingIntent);
    Intent intent = new Intent(context, NotificationDeletedReceiver.class);
    intent.putExtra(KlyphBundleExtras.NOTIFICATION_ID, notification.getNotification_id());
    int random = (int) Math.round(Math.random() * 100000);
    builder.setDeleteIntent(PendingIntent.getBroadcast(context.getApplicationContext(), random, intent, 0));
    final NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Log.d("NotificationService", "Notify " + notification.getNotification_id());
    final String tag = context.getPackageName() + "_" + notification.getNotification_id();
    // pair (tag, id) must be unique
    // because notificationId may not be converted to an int
    // tag is the unique key
    mNotificationManager.notify(tag, 0, builder.build());
}
Also used : ImageActivity(com.abewy.android.apps.klyph.app.ImageActivity) NotificationManager(android.app.NotificationManager) StreamActivity(com.abewy.android.apps.klyph.app.StreamActivity) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.support.v4.app.TaskStackBuilder) EventActivity(com.abewy.android.apps.klyph.app.EventActivity) GroupActivity(com.abewy.android.apps.klyph.app.GroupActivity)

Example 20 with Builder

use of android.support.v4.app.NotificationCompat.Builder in project android-simpl3r by jgilfelt.

the class UploadService method buildNotification.

private Notification buildNotification(String msg, int progress) {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setWhen(System.currentTimeMillis());
    builder.setTicker(msg);
    builder.setContentTitle(getString(R.string.app_name));
    builder.setContentText(msg);
    builder.setSmallIcon(R.drawable.ic_stat_uploading);
    builder.setOngoing(true);
    builder.setProgress(100, progress, false);
    Intent notificationIntent = new Intent(this, MainActivity.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    builder.setContentIntent(contentIntent);
    return builder.build();
}
Also used : NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Aggregations

NotificationCompat (android.support.v4.app.NotificationCompat)105 PendingIntent (android.app.PendingIntent)86 Intent (android.content.Intent)76 NotificationManager (android.app.NotificationManager)35 Notification (android.app.Notification)29 Builder (android.support.v4.app.NotificationCompat.Builder)19 Context (android.content.Context)16 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)14 Uri (android.net.Uri)11 Bundle (android.os.Bundle)10 Bitmap (android.graphics.Bitmap)9 View (android.view.View)9 RemoteViews (android.widget.RemoteViews)9 IOException (java.io.IOException)9 AlertDialog (android.app.AlertDialog)7 DialogInterface (android.content.DialogInterface)7 Paint (android.graphics.Paint)6 SpannableString (android.text.SpannableString)6 TypedValue (android.util.TypedValue)6 TextView (android.widget.TextView)6