android notification 通知

來源:互聯網
上載者:User

標籤:android   style   blog   io   color   ar   使用   sp   div   

 1 public class NotificationTest extends Activity 2 { 3     static final int NOTIFICATION_ID = 0x123; 4     NotificationManager nm; 5  6     @Override 7     public void onCreate(Bundle savedInstanceState) 8     { 9         super.onCreate(savedInstanceState);10         setContentView(R.layout.main);11         // 擷取系統的NotificationManager服務12         nm = (NotificationManager) 13             getSystemService(NOTIFICATION_SERVICE);14     }15 16     // 為發送通知的按鈕的點擊事件定義事件處理方法 17     public void send(View source)18     {19         // 建立一個啟動其他Activity的Intent20         Intent intent = new Intent(NotificationTest.this21             , OtherActivity.class);22         PendingIntent pi = PendingIntent.getActivity(23             NotificationTest.this, 0, intent, 0);24         Notification notify = new Notification.Builder(this)25             // 設定開啟該通知,該通知自動消失26             .setAutoCancel(true)27             // 設定顯示在狀態列的通知提示資訊28             .setTicker("有新訊息")29             // 設定通知的表徵圖30             .setSmallIcon(R.drawable.notify)31             // 設定通知內容的標題32             .setContentTitle("一條新通知")33             // 設定通知內容34             .setContentText("恭喜你,您加薪了,工資增加20%!")35             // // 設定使用系統預設的聲音、預設LED燈36             // .setDefaults(Notification.DEFAULT_SOUND37             // |Notification.DEFAULT_LIGHTS)38             // 設定通知的自訂聲音39             .setSound(Uri.parse("android.resource://org.crazyit.ui/"40                 + R.raw.msg))41             .setWhen(System.currentTimeMillis())42             // 設改通知將要啟動程式的Intent43             .setContentIntent(pi).build();44         // 發送通知45         nm.notify(NOTIFICATION_ID, notify);46     }47 48     // 為刪除通知的按鈕的點擊事件定義事件處理方法49     public void del(View v)50     {51         // 取消通知52         nm.cancel(NOTIFICATION_ID);53     }54 }

 

android notification 通知

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.