Android中Notification的使用

来源:互联网 发布:手机淘宝联盟自己购买 编辑:程序博客网 时间:2024/05/01 11:55
Notification在通知栏发送通知以进行消息提醒
private int NOTIFICATION_ID = 0;//设置Notification的ID以便后续更新消息内容    Intent intent = new Intent(getApplicationContext(), MainActivity.class);//设置一个Intent进行点击后的操作        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);//设置点击后跳转到Intent    Builder builder = new Builder(MainActivity.this);//此处需要引用android.support.v7.app.NotificationCompat.Builder        builder.setSmallIcon(R.drawable.ic_luancher);//设置Notification图标        builder.setContentTitle("新消息!");//设置Notification的标题        builder.setContentText("您有新消息!");//设置Notification的内容    builder.setSubText("消息的详细内容!");//设置Notification的扩展信息        builder.setAutoCancel(true);//设置Notification可以清除    builder.setContentIntent(pendingIntent);//设置点击后跳转到Intent        Notification notification = builder.build();//创建并获取Notification的真实对象        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);//获取服务        notificationManager.notify(NOTIFICATION_ID,notification);//ID用于后续更新Notification内容
0 0
原创粉丝点击