Android学习笔记--android——Notification

android Notification
    是显示在手机状态栏上的通知,具有全局效果的通知
    时效性不强
    
    步骤:
    // 获得系统服务
    NotificationManager mNotificationManager
   = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    
    // 创建一个Notification对象
    Notification notification = new Notification(R.drawable.ic_launcher,
            "短信来了", System.currentTimeMillis());
    // 设置点击事件关联activity
    Intent intent = new Intent(this, SecondActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,intent, 0);
    // 设置标题跟内容
    notification.setLatestEventInfo(this, "小丽", "在么", contentIntent);
    // 发送通知
    mNotificationManager.notify(0, notification);                

    
    // 点击之后,消失
    //  notification.flags = Notification.FLAG_AUTO_CANCEL;
    // 点击之后,不会消失
        notification.flags = Notification.FLAG_ONGOING_EVENT;

    
    取消通知:
    mNotificationManager.cancel(0);//参数必须是之前发送通知的id

成都创新互联专业为企业提供朝天网站建设、朝天做网站、朝天网站设计、朝天网站制作等企业网站建设、网页设计与制作、朝天企业网站模板建站服务,10年朝天做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。


网页题目:Android学习笔记--android——Notification
文章起源:http://hxwzsj.com/article/jhjcpc.html

其他资讯

Copyright © 2025 青羊区翔捷宏鑫字牌设计制作工作室(个体工商户) All Rights Reserved 蜀ICP备2025123194号-14
友情链接: 重庆网站建设 网站建设方案 成都网站建设 成都网站设计 成都商城网站建设 LED网站设计方案 成都营销网站制作 自适应网站设计 手机网站制作 成都网站制作 四川成都网站设计 成都网站建设 成都商城网站建设 移动手机网站制作 企业网站建设公司 网站设计 高端网站设计 成都网站设计 阿坝网站设计 成都网站建设推广 营销型网站建设 网站建设