標籤:android style blog http color java os io
該應用的介面如下,介面代碼在此不再給出
MainActivity.java
1 public class MainActivity extends Activity { 2 private TextView tvTitle; 3 private TextView tvContent; 4 private Button btnSend; 5 private String title; 6 private String content; 7 8 public void onCreate(Bundle savedInstanceState) { 9 super.onCreate(savedInstanceState);10 setContentView(R.layout.activity_main);11 12 tvTitle=(TextView) findViewById(R.id.editText1);13 tvContent=(TextView) findViewById(R.id.EditText01);14 btnSend=(Button) findViewById(R.id.btnSend);15 16 btnSend.setOnClickListener(new OnClickListener(){17 18 @Override19 public void onClick(View v) {20 // TODO Auto-generated method stub21 send();22 }23 });24 25 }26 public void send(){27 title=tvTitle.getText().toString();//標題28 content=tvContent.getText().toString();//內容29 30 //1.得到NotificationManager服務31 NotificationManager nm=(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);32 //2.執行個體化一個通知,指定表徵圖、概要、時間33 Notification n = new Notification(R.drawable.ic_launcher,"通知",System.currentTimeMillis());34 //3.指定通知的標題、內容和intent35 Intent intent = new Intent(this, MainActivity.class);36 PendingIntent pi= PendingIntent.getActivity(this, 0, intent, 0);37 n.setLatestEventInfo(this, title, content, pi);38 //指定聲音39 //n.defaults = Notification.DEFAULT_SOUND; 40 //4.發送通知41 nm.notify(1, n);42 }43 44 }
點擊“發送”按鈕,即可在通知欄顯示發送的訊息!