package notification_test.test.run;import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;public class Main extends Activity {
private Button button1;
private Button button2; private final String notifictionService = Context.NOTIFICATION_SERVICE;
private final int icon = R.drawable.icon;
private static int createdNums = 0;
private final String tickerText = "通知内容:该起床了!"; @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button startNotificationButton = (Button) findViewById(R.id.button1); startNotificationButton.setOnClickListener(new OnClickListener() { public void onClick(View arg0) {
NotificationManager notificationManager = (NotificationManager) getSystemService(notifictionService);
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText,
when);
String contentTitle = "学校通知";
String contentText = "6:30分必须起床,否则罚跑操场10圈!!!!!!!!";
Intent notificationIntent = new Intent(Main.this,
ShowInfo.class); PendingIntent contentIntent = PendingIntent.getActivity(
getApplicationContext(), 0, notificationIntent,
Intent.FLAG_ACTIVITY_NEW_TASK);// 在通知栏启动Activity,并打开新的Task栈
notification.setLatestEventInfo(Main.this, contentTitle,
contentText, contentIntent);
notification.defaults |= Notification.DEFAULT_LIGHTS;
notificationManager.notify(3, notification); } });
}}启动不了ShowInfo