极品飞车9解压密码,得失不萦于怀,龙年快乐电影最新地址2016
android状态栏提醒
在android中提醒功能也可以用alertdialog,但是我们要慎重的使用,因为当使用alertdialog的时候,用户正在进行的操作将会被打断,因为当前焦点被alertdialog得到。我们可以想像一下,当用户打游戏正爽的时候,这时候来了一条短信。如果这时候短信用alertdialog提醒,用户必须先去处理这条提醒,从而才能继续游戏。用户可能会活活被气死。而使用notification就不会带来这些麻烦事,用户完全可以打完游戏再去看这条短信。所以在开发中应根据实际需求,选择合适的控件。
步骤:
一、添加布局对象
<button
android:id="@+id/cancelbutton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="cancelnotification" />
@override
protected void oncreate(bundle savedinstancestate) {
super.oncreate(savedinstancestate);
setcontentview(r.layout.activity_main);
setupviews();
}
private void setupviews() {
showbtn = (button) findviewbyid(r.id.showbutton);
calclebtn = (button) findviewbyid(r.id.cancelbutton);
noti = new notification(r.drawable.ic_launcher, "this is a notification", system.currenttimemillis());
noti.defaults = notification.default_sound;// 使用默认的提示声音
noti.defaults |= notification.default_vibrate;// 添加震动
notimanger = (notificationmanager) this.getsystemservice(mcontext.notification_service);//获取nofificationmanger对象
showbtn.setonclicklistener(this);//让activity实现接口onclicklistener可以简单的通过此两行代码添加按钮点击响应事件
calclebtn.setonclicklistener(this);
}
// 按钮点击事件响应
@override
public void onclick(view v) {
if (v == showbtn) {
intent intent = new intent(this.getapplicationcontext(),this.getclass());
// 设置intent.flag_activity_new_task
intent.setflags(intent.flag_activity_new_task);
pendingintent contentintent = pendingintent.getactivity(this, 0, intent, 0);
// noti.setlatesteventinfo(context, contenttitle, contenttext, contentintent)设置(上下文,标题,内容,pendinginteng)
noti.setlatesteventinfo(this, "10086", "你从此以后免除所有话费", contentintent);
// 发送通知(消息id,通知对象)
notimanger.notify(notification_id, noti);
} else if (v == calclebtn) {
// 取消通知(id)
notimanger.cancel(notification_id);
}
}
}
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Android studio开发小型对话机器人app(实例代码)
Android通过Java sdk的方式接入OpenCv的方法
Android 通过cmake的方式接入opencv的方法步骤
Android Studio finish()方法的使用与解决app点击“返回”(直接退出)
Android 进度条 ProgressBar的实现代码(隐藏、出现、加载进度)
网友评论