0703-APP-Notification-statue-bar

來源:互聯網
上載者:User

標籤: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




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.