l通过一个按钮点击,然后在在通知栏显示通知信息;
package cn.core.test;import android.app.Activity;import android.app.Notification;import android.app.NotificationManager;import android.app.PendingIntent;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;public class MainActivity extends Activity implements OnClickListener { private Button button1 = null, button2 = null; private NotificationManager mNotificationManager = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button1 = (Button) findViewById(R.id.button1); button1.setOnClickListener(this); button2 = (Button) findViewById(R.id.button2); button2.setOnClickListener(this); } @Override public void onClick(View v) { if(v==button1) {// Notification mNotification = new Notification();// mNotification.icon=;// mNotification.tickerText=;// mNotification.when=;// Notification mNotification = new Notification( android.R.drawable.presence_online, "通知", System.currentTimeMillis()); mNotification.defaults = Notification.DEFAULT_VIBRATE; Intent intent = new Intent(MainActivity.this, Activity01.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0); mNotification.setLatestEventInfo(this, "开会通知11", "通知您下午17:60分在卫生间开会", pendingIntent); mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); mNotificationManager.notify(11111, mNotification); } else if(v==button2) { mNotificationManager.cancelAll(); } }}