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