實現(xiàn)代碼如下,代碼中有詳細注釋:
- public class MainActivity extends Activity {
- private TextView tvTitle;
- private TextView tvContent;
- private Button btnSend;
- private String title;
- private String content;
-
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
-
- tvTitle=(TextView) findViewById(R.id.etTitle);
- tvContent=(TextView) findViewById(R.id.etContent);
- btnSend=(Button) findViewById(R.id.btnSend);
-
- btnSend.setOnClickListener(new OnClickListener(){
- public void onClick(View v) {
- send();
- }
- });
-
- }
- public void send(){
- title=tvTitle.getText().toString();
- content=tvContent.getText().toString();
-
-
- NotificationManager nm=(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
-
- Notification n=new Notification(R.drawable.ic_launcher,"通知",System.currentTimeMillis());
-
- Intent intent = new Intent(this, MainActivity.class);
- PendingIntent pi= PendingIntent.getActivity(this, 0, intent, 0);
- n.setLatestEventInfo(this, title, content, pi);
-
-
-
- nm.notify(1, n);
- }
-
- }
該文章在 2013/2/25 14:43:52 編輯過