public class Main extends Activity {
NotificationManager objNotificationManager;
Notification
objNotification;
PendingIntent
objPendingIntent;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// 声明通知(消息)管理器 只要知道它是用来管理通知消息的就行了
objNotificationManager = (NotificationManager) getSystemService( NOTIFICATION_SERVICE );
int icon = R.drawable.icon;
CharSequence tickerText = "小图标旁的文字";
objNotification = new Notification( icon,tickerText,System.currentTimeMillis() );
// 如果有振动或者全部提示方式,必须在 AndroidManifest.xml 加入振动权限
objPendingIntent = PendingIntent.getActivity( this,
0,
new Intent(this,Main.class ),
0 );
objNotification.setLatestEventInfo( this,"通知栏的标题","通知栏的内容",objPendingIntent );
// 添加入通知管理器中
objNotificationManager.notify( 0,objNotification );
}
}
}