公共类LayoutActivity扩展AppCompatActivity{Button NOTIFYBTN;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_layout);
notifybtn=(Button) findViewById(R.id.button_noti);
notifybtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent();
PendingIntent pIntent = PendingIntent.getActivity(LayoutActivity.this,0,intent,0);
Notification noti = new Notification.Builder(LayoutActivity.this)
.setTicker("Ticker Title")
.setContentTitle("Content Title")
.setContentText("Bus has Arrived at the station")
.setSmallIcon(R.drawable.aaa)
.addAction(R.drawable.aaa,"Available",pIntent)
.addAction(R.drawable.aaa,"NotAvailable",pIntent)
.setContentIntent(pIntent).getNotification();
noti.flags = Notification.FLAG_AUTO_CANCEL;
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.notify(0,noti);
}
});
}
}
使通知在15分钟内消失? 小图标支持任何类型的图像吗?
对于notification.builder,我相信您需要设置SetTimeOutAfter。