zoukankan      html  css  js  c++  java
  • android Notification 的使用

    android Notification 的使用

    http://www.cnblogs.com/newcj/archive/2011/03/14/1983782.html

    Android 状态栏通知Notification用法

    http://www.pocketdigi.com/20100905/89.html

    android清除通知栏消息

    http://www.2cto.com/kf/201201/116590.html

     

    public class SmsNotification {
        public static void showSmsNotification(Context context) {
            List<TxrjMessage> list = SmsDataManager.getUnreadMessages(context);
            if(list.size()>0){
                notify(context, list.get(0));
            }
        }
        public static void notify(Context context, TxrjMessage msg) {
            NotificationManager notifiMgr = (NotificationManager) context
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            /*Notification notifi = new Notification(R.drawable.sms_icon,
                    "短信", System.currentTimeMillis());    */
            Notification notifi = new Notification();
            notifi.icon = R.drawable.sms_icon;
            notifi.tickerText = msg.getBody();
            notifi.when = System.currentTimeMillis();
            notifi.number = 1;
            /*notifi.flags = Notification.FLAG_ONGOING_EVENT
                    | Notification.FLAG_NO_CLEAR | Notification.FLAG_SHOW_LIGHTS;*/
            notifi.defaults = Notification.DEFAULT_ALL;
            Intent itNotifi = new Intent(context, MessageListActivity.class);
            String displayName = TextUtils.isEmpty(msg.getName()) ? msg.getNumber() : msg.getName();
            itNotifi.putExtra(TxrjConstant.EXTRA_THREAD_DISPLAY_NAME, displayName);
            itNotifi.putExtra(TxrjConstant.EXTRA_THREAD_NUMBER, msg.getNumber());
            PendingIntent pendIt = PendingIntent.getActivity(context,
                    TxrjConstant.REQUEST_READ_NOTIFICATION, itNotifi, 0);
            Log.i("txrjsms", "name:"+msg.getName()+", number:"+msg.getNumber());
            notifi.setLatestEventInfo(context, displayName, msg.getBody(), pendIt);
            notifiMgr.notify(0, notifi);
        }
    }

    Field-Type

    Field-Name

    Description

    public static final Creator<Notification>

    CREATOR

    Parcelable.Creator that instantiates Notification objects

    public int

    audioStreamType

    The audio stream type to use when playing the sound. Should be one of the STREAM_ constants from AudioManager.

    public RemoteViews

    bigContentView

    A large-format version of contentView, giving the Notification an opportunity to show more detail. The system UI may choose to show this instead of the normal content view at its discretion.

    public PendingIntent

    contentIntent

    The intent to execute when the expanded status entry is clicked. If this is an activity, it must include theFLAG_ACTIVITY_NEW_TASK flag, which requires that you take care of task management as described in the Tasks and Back Stackdocument. In particular, make sure to read the notification section Handling Notifications for the correct ways to launch an application from a notification.

    public RemoteViews

    contentView

    The view that will represent this notification in the expanded status bar.

    public int

    defaults

    Specifies which values should be taken from the defaults. To set, OR the desired from DEFAULT_SOUND, DEFAULT_VIBRATE, DEFAULT_LIGHTS. For all default values, use DEFAULT_ALL.

    public PendingIntent

    deleteIntent

    The intent to execute when the notification is explicitly dismissed by the user, either with the "Clear All" button or by swiping it away individually. This probably shouldn't be launching an activity since several of those will be sent at the same time.

    public int

    flags

     

    public PendingIntent

    fullScreenIntent

    An intent to launch instead of posting the notification to the status bar.

    public int

    icon

    The resource id of a drawable to use as the icon in the status bar.

    public int

    iconLevel

    If the icon in the status bar is to have more than one level, you can set this.

    public Bitmap

    largeIcon

    The bitmap that may escape the bounds of the panel and bar.

    public int

    ledARGB

    The color of the led.

    public int

    ledOffMS

    The number of milliseconds for the LED to be off while it's flashing.

    public int

    ledOnMS

    The number of milliseconds for the LED to be on while it's flashing.

    public int

    number

    The number of events that this notification represents.

    public int

    priority

    Relative priority for this notification.

    public Uri

    sound

    The sound to play.

    public CharSequence

    tickerText

    Text to scroll across the screen when this item is added to the status bar on large and smaller devices.

    public RemoteViews

    tickerView

    The view to show as the ticker in the status bar when the notification is posted.

    public long[]

    vibrate

    The pattern with which to vibrate.

    public long

    when

    A timestamp related to this notification, in milliseconds since the epoch.

  • 相关阅读:
    禁止页面缓存 移动端
    常见的请求头与响应头介绍
    阮一峰 ES6学习
    禁止页面缩放 移动端
    10月30日学习日志
    11月7日学习日志
    11月6日学习日志
    10月31日学习日志
    11月1日学习日志
    11月9日学习日志
  • 原文地址:https://www.cnblogs.com/fengzhblog/p/3203127.html
Copyright © 2011-2022 走看看