build Notification Pre Honeycomb - Android Android OS

Android examples for Android OS:Notification Create

Description

build Notification Pre Honeycomb

Demo Code


//package com.java2s;

import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;

import java.lang.reflect.Method;

public class Main {
    @SuppressWarnings("deprecation")
    private static Notification buildNotificationPreHoneycomb(
            Context context, PendingIntent pendingIntent, String title,
            String text, int iconId) {
        Notification notification = new Notification(iconId, "",
                System.currentTimeMillis());
        try {/*from ww w . j  a v  a2  s  . c  o  m*/
            // try to call "setLatestEventInfo" if available
            Method m = notification.getClass().getMethod(
                    "setLatestEventInfo", Context.class,
                    CharSequence.class, CharSequence.class,
                    PendingIntent.class);
            m.invoke(notification, context, title, text, pendingIntent);
            notification.flags &= Notification.FLAG_AUTO_CANCEL;
        } catch (Exception e) {
            // do nothing
        }
        return notification;
    }
}

Related Tutorials