[英]How to Make an Android Notification Expire in a specific time?
public class LayoutActivity extends AppCompatActivity { Button notifybtn;公共 class LayoutActivity 扩展 AppCompatActivity { 按钮 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);
}
});
}
} }
make the notification dissapear in 15min?让通知在 15 分钟内消失? and does small icon support any type of image?小图标是否支持任何类型的图像?
For Notification.Builder, I believe you need to set setTimeoutAfter.对于 Notification.Builder,我相信你需要设置 setTimeoutAfter。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.