码迷,mamicode.com
首页 > 移动开发 > 详细

0703-APP-Notification-statue-bar

时间:2014-05-13 00:02:35      阅读:465      评论:0      收藏:0      [点我收藏+]

标签:blog   class   code   java   c   ext   

1.展示显示textTicker和只有icon的两种情况:当参数showTicker为true时显示否则不显示

        // In this sample, we‘ll use the same text for the ticker and the expanded notification
        CharSequence text = getText(textId);

        // choose the ticker text
        String tickerText = showTicker ? getString(textId) : null;

        // Set the icon, scrolling text and timestamp
        Notification notification = new Notification(moodId, tickerText,
                System.currentTimeMillis());

        // Set the info for the views that show in the notification panel.
        notification.setLatestEventInfo(this, getText(R.string.status_bar_notifications_mood_title),
                       text, makeMoodIntent(moodId));

        // Send the notification.
        // We use a layout id because it is a unique number.  We use it later to cancel.
        mNotificationManager.notify(R.layout.status_bar_notifications, notification);
    

2.展示通过iew创建notifaction


   // Instead of the normal constructor, we‘re going to use the one with no args and fill
        // in all of the data ourselves.  The normal one uses the default layout for notifications.
        // You probably want that in most cases, but if you want to do something custom, you
        // can set the contentView field to your own RemoteViews object.
        Notification notif = new Notification();

        // This is who should be launched if the user selects our notification.
        notif.contentIntent  = PendingIntent.getActivity(this, 0,
                new Intent(this, NotificationDisplay.class)
        .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        .putExtra("moodimg", moodId),
PendingIntent.FLAG_UPDATE_CURRENT);

        // In this sample, we‘ll use the same text for the ticker and the expanded notification
        CharSequence text = getText(textId);
        notif.tickerText = text;
  


notifacation 设置声音和震动

        
        // This method sets the defaults on the notification before posting it.
        
        // This is who should be launched if the user selects our notification.
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                new Intent(this, StatusBarNotifications.class), 0);

        // In this sample, we‘ll use the same text for the ticker and the expanded notification
        CharSequence text = getText(R.string.status_bar_notifications_happy_message);

        final Notification notification = new Notification(
                R.drawable.stat_happy,       // the icon for the status bar
                text,                        // the text to display in the ticker
                System.currentTimeMillis()); // the timestamp for the notification

        notification.setLatestEventInfo(
                this,                        // the context to use
                getText(R.string.status_bar_notifications_mood_title),
                                             // the title for the notification
                text,                        // the details to display in the notification
                contentIntent);              // the contentIntent (see above)

        notification.defaults = defaults;
        
        mNotificationManager.notify(
                   R.layout.status_bar_notifications, // we use a string id because it is a unique
                                                      // number.  we use it later to cancel the
                   notification);                     // notification
    }    



        // the icon for the status bar
        notif.icon = moodId;

        // our custom view
        RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.status_bar_balloon);
        contentView.setTextViewText(R.id.text, text);
        contentView.setImageViewResource(R.id.icon, moodId);
        notif.contentView = contentView;

        // we use a string id because is a unique number.  we use it later to cancel the
        // notification
        mNotificationManager.notify(R.layout.status_bar_notifications, notif);

默认值有:Notification.DEFAULT_SOUND、Notification.DEFAULT_VIBRATE、Notification.DEFAULT_ALL




0703-APP-Notification-statue-bar,布布扣,bubuko.com

0703-APP-Notification-statue-bar

标签:blog   class   code   java   c   ext   

原文地址:http://blog.csdn.net/zhi07/article/details/25646799

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!