Android——Notification的使用

目录

Notification
NotificationBuilder

Notification

 private void showNotification() {
        Notification notification=new Notification();//初始化notification
        notification.icon= R.mipmap.ic_launcher;//设置通知的图片
        notification.tickerText="我是一个消息";//设置状态栏的文本
        notification.flags=Notification.FLAG_AUTO_CANCEL;//设置为 可以取消
        Intent intent=new Intent(getApplicationContext(),MainActivity.class);//设置pendingIntent事件
        PendingIntent pend=PendingIntent.getActivity(getApplicationContext(),1, intent, PendingIntent.FLAG_ONE_SHOT);//设置pendingInten使用方式
        notification.setLatestEventInfo(getApplicationContext(),"我是一个标题","我是内容",pend);
        notification.when=System.currentTimeMillis();//设置显示通知的时间
        mNotificationManager.notify(1,notification); //将通知发送给id为1的用户
    }
    ![这里写图片描述](http://img.blog.csdn.net/20150830092248962)

NotificationBuilder

    private void showNotificationBuilder() {
        Intent intent=new Intent(getApplicationContext(),MainActivity.class);//设置pendingIntent事件
        PendingIntent pend=PendingIntent.getActivity(getApplicationContext(),1, intent, PendingIntent.FLAG_ONE_SHOT);//设置pendingInten使用方式
        Notification notification=new Notification.Builder(MainActivity.this).setSmallIcon(R.mipmap.ic_launcher).setTicker("我是一条消息").setContentTitle("我是标题")
                .setContentText("我是文本吧").setContentInfo("我是消息").setShowWhen(true).setAutoCancel(true).build();
        mNotificationManager.notify(2,notification);
    }

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值