Notification.Builder
package com.example.notificationtest;
import android.app.Activity;
import android.app.Notification;
import android.app.Notification.Builder;
import android.app.NotificationManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
private final int NOTIFICATION_BASE_NUMBER=110;
private Notification n = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button bn = (Button)findViewById(R.id.bn);
bn.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Builder notification = new Notification.Builder(MainActivity.this);
notification.setSmallIcon(R.drawable.ic_launcher)
.setTicker("通知来了!!")
.setAutoCancel(false)
.setContentTitle("这是标题~")
.setContentText("这是内容");
n = notification.getNotification();
manager.notify(1 , n);
}});
}
}