zoukankan      html  css  js  c++  java
  • 发送Notification

    //1、获得通知管理者
    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    //2、创建Intent 对象
    Intent intent = new Intent(this,OtherActivity.class);

    //3、创建PendingIntent对象
    PendingItent pend = PendingIntent.getactivity(act, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    //4、创建NotificationComPat 兼容对象

    NotificationCompat.Builder compat = new Builder(act);

    compat.setContentTitle("提示"); //设置标题
    compat.setContentText("系统可以更新");//设置内容
    compat.setSmallIcon(android.R.drawable.ic_dialog_alert);//设置图标
    compat.setWhen(System.currentTimeMillis());//设置时间
    compat.setTicker("你有新的消息");//第一次会在状态栏显示提示语
    compat.setDefaults(Notification.DEFAULT_SOUND);//设置默认提示音
    compat.setAutoCancel(true);//设置自动维护
    compat.setContentIntent(pend); //设置要传递的意图

    //5、通知管理
    nm.notify(0,pend.build);

  • 相关阅读:
    博客园——程序员
    PHP获取IP
    VIM使用笔记
    再见,帕金!
    A Song of My Heart
    读书...
    纪念日...
    一路向北
    韬光养晦,希望能有所作为
    一首好歌!
  • 原文地址:https://www.cnblogs.com/pbq-dream/p/5348351.html
Copyright © 2011-2022 走看看