notification With Big View - Android User Interface

Android examples for User Interface:View

Description

notification With Big View

Demo Code


import android.app.Activity;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v4.app.RemoteInput;
import java.io.IOException;

public class Main{
    private static final int NOTIFICATION_ID = 1;
    public static void notificationWithBigView(Context ctx) {
        Intent viewIntent = new Intent(ctx, MainActivity.class);
        PendingIntent viewPendingIntent = PendingIntent.getActivity(ctx, 0,
                viewIntent, 0);/*w ww  .  java2s.c om*/

        NotificationCompat.BigTextStyle bigStyle = new NotificationCompat.BigTextStyle();
        bigStyle.bigText("asdf");

        NotificationCompat.Builder notificationBuilder = newNotification(
                ctx, "BigView", null).setLargeIcon(getPhoto(ctx))
                .setContentIntent(viewPendingIntent).setStyle(bigStyle);
        dispatchNotification(ctx, notificationBuilder.build(),
                NOTIFICATION_ID);
    }
    private static NotificationCompat.Builder newNotification(Context ctx,
            String title, String text) {

        return new NotificationCompat.Builder(ctx)
                .setSmallIcon(R.drawable.ic_like).setContentTitle(title)
                .setContentText(text).setAutoCancel(true)
                .setDefaults(NotificationCompat.DEFAULT_ALL);
    }
    private static Bitmap getPhoto(Context ctx) {
        Bitmap photo = null;
        try {
            photo = BitmapFactory.decodeStream(ctx.getAssets().open(
                    "my_photo.jpg"));
        } catch (IOException ioex) {
        }

        return photo;
    }
    private static void dispatchNotification(Context ctx,
            Notification notification, int id) {

        NotificationManagerCompat notificationManager = NotificationManagerCompat
                .from(ctx);
        notificationManager.notify(id, notification);
    }
}

Related Tutorials