Android任务栏通知

        private static int nId = 0;

        private void RaiseSysTrayAlert(List<NEventBean> eventList)
        {
            NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            Context context = getApplicationContext();

            for(NEventBean bean : eventList)
            {
                Builder mBuilder = new Builder(context);
                mBuilder.setTicker("XXXX");
                mBuilder.setSmallIcon(R.drawable.ic_launcher);
                mBuilder.setContentTitle("XXXX");
                mBuilder.setContentText(bean.msg);
                mBuilder.setAutoCancel(true);

                Intent notifyIntent = new Intent(context, MainActivity.class);
                notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                PendingIntent pIntent = PendingIntent.getActivity(context, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
                mBuilder.setContentIntent(pIntent);

                nId++;
                nm.notify(nId, mBuilder.build());
            }
        }

Comments are closed.