Notification的使用
来源:互联网 发布:js如何获取当前时间 编辑:程序博客网 时间:2024/05/24 05:10
public class MainActivity extends Activity implements OnClickListener{private Button send;private Button cancel;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_noti);send = (Button)findViewById(R.id.btn_send);cancel = (Button)findViewById(R.id.btn_cancel);send.setOnClickListener(this);cancel.setOnClickListener(this);}@Overridepublic void onClick(View v) {if (v.getId() == R.id.btn_send) {send();} else {cancel();}}private int id = 1325353;private int id2 = 1325353;private int i = 0;private void send() {Builder builder = new Notification.Builder(this);builder.setSmallIcon(R.drawable.ic_launcher);/** * 状态栏的提示 */builder.setTicker("您有了一条新的消息");builder.setContentTitle("coding for fun!" + i++);builder.setWhen(System.currentTimeMillis());builder.setContentText("你好");builder.setNumber(id);Intent my = new Intent(this, com.robot.ok315.MainActivity.class);PendingIntent intent = PendingIntent.getActivity(this, 0, my, PendingIntent.FLAG_NO_CREATE);builder.setContentIntent(intent);builder.setDefaults(Notification.DEFAULT_SOUND);builder.setDefaults(Notification.DEFAULT_LIGHTS); // 需要设置权限builder.setDefaults(Notification.DEFAULT_VIBRATE); // 需要设置权限// builder.setDefaults(Notification.DEFAULT_VIBRATE); // 设置声音,指示灯,震动NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);notificationManager.notify(id, builder.getNotification());}private void cancel() {NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);notificationManager.cancel(id2);}}
注意:如果Notification的id相同,则只会生成一条通知信息。
0 0
- 3. Notification的使用
- 3、Notification的使用
- Android-Notification的使用
- Android Notification的使用
- android Notification 的使用
- android Notification 的使用
- Android Notification 的使用
- Android-Notification的使用
- android Notification 的使用
- 使用自定义的 Notification
- Notification的使用详解
- android Notification 的使用
- android Notification 的使用
- android Notification 的使用
- Notification 的使用
- android Notification 的使用
- android Notification的使用
- Notification的使用
- STL map的遍历与pair的使用
- DayDayUP_Python自学记录[2]_Python变量类型
- 我是SB
- 高校云平台(五):移动开发之环境搭建
- Android 自定义View:实现View的滑动效果
- Notification的使用
- hdu 1753 大明A+B 长小数相加
- Android Studio引用Library与导入jar
- js获取浏览器高度和宽度值(多浏览器)
- .NET实验7-1
- React Native 开发(第一篇)
- 服务器端Json生成及Android客户端的json解析
- ZOJ 3946 Highway Project SPFA 两个限制条件
- Balanced Lineup(线段树)