create Resident Notification - Android Android OS

Android examples for Android OS:Notification Create

Description

create Resident Notification

Demo Code


//package com.java2s;
import android.app.Notification;

import android.app.PendingIntent;

import android.content.Context;
import android.content.Intent;
import android.widget.RemoteViews;

public class Main {

    @SuppressWarnings("deprecation")
    public static Notification creatResidentNotification(Context context,
            int notificationId, int statusBarIcon, Intent intent,
            RemoteViews view, String notice, int notificationFlag) {

        Notification notification = new Notification(statusBarIcon, notice,
                System.currentTimeMillis());

        notification.contentView = view;
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                | Intent.FLAG_ACTIVITY_NEW_TASK);

        notification.flags = notificationFlag;

        PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
                intent, PendingIntent.FLAG_UPDATE_CURRENT);
        notification.contentIntent = contentIntent;
        // notification.setLatestEventInfo(context, title, content,
        // contentIntent);

        return notification;
    }//from  w  ww.ja  v  a 2 s  .co  m
}

Related Tutorials