zoukankan      html  css  js  c++  java
  • Android 中的通知

       一般手机上边都有一个状态条,显示电池电量、信号强度、未接来电、短信...Android 的屏幕上方也具有状态条。这里所说的通知,就是在这个状态条上显示通知。

    发送通知的步骤如下:
      1).获取通知管理器

    NotificationManager mNotificationManager = (NotificationManager)     
    getSystemService(Context.NOTIFICATION_SERVICE); 

      2).新建一个通知,指定其图标和标题  

    int icon = android.R.drawable.stat_notify_chat;
    long when = System.currentTimeMillis();
    
    //第一个参数为图标,第二个参数为标题,第三个为通知时间
    Notification notification = new Notification(icon, null, when);
    
    Intent openintent = new Intent(this, OtherActivity.class);
    //当点击消息时就会向系统发送 openintent 意图
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, openintent, 0);
    notification.setLatestEventInfo(this, “标题”, “内容", contentIntent);
    mNotificationManager.notify(0, notification); 
  • 相关阅读:
    multi-task learning
    代码杂谈-python函数
    代码杂谈-or符号
    安装maven
    zsh
    mint linux的几个问题
    [软件] Omnigraffle
    无梯度优化算法
    根据pdf文件获取标题等信息
    计算广告-GD广告
  • 原文地址:https://www.cnblogs.com/rfheh/p/4167329.html
Copyright © 2011-2022 走看看