set View Notification - Android User Interface

Android examples for User Interface:View

Description

set View Notification

Demo Code


//package com.java2s;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

import android.support.v4.app.NotificationCompat;
import android.widget.RemoteViews;

public class Main {

    public static void setViewNotification(Context context, int layoutId,
            int viewId, String title, String content, String ticker,
            int sIcon, Class<?> cls) {
        NotificationManager manager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                context);//from www  .j  ava 2  s  . c om
        RemoteViews views = new RemoteViews(context.getPackageName(),
                layoutId);
        views.setImageViewResource(viewId, sIcon);
        views.setTextViewText(viewId, title);
        views.setTextViewText(viewId, content);

        mBuilder.setContent(views);
        // 
        mBuilder.setTicker(ticker);
        // ?
        mBuilder.setAutoCancel(true);

        Intent intent = new Intent(context, cls);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
                intent, PendingIntent.FLAG_UPDATE_CURRENT);

        mBuilder.setContentIntent(pendingIntent);
        manager.notify(0, mBuilder.build());
    }
}

Related Tutorials