zoukankan      html  css  js  c++  java
  • notification

    3种notification:

    1. Dialog 循环进度条:适合前端activity。

    2. Toast: 不需要用户干预, service也可。

    默认: Toast.makeText(context, text, duration).show();
    设置显示位置:toast.setGravity(Gravity.CENTER_VERTICAL,0,0);
    自定义view:toast.setView(layout);

    3. Status notification: 适合service引起用户注意。

    Status notification较复杂,如下:

    1、获得service:nm = getSystemService(Context.NOTIFICATION_SERVICE);

    2、定义PendingIntent:PendingIntent.getActivity(this, 0, new Intent(this, MyClass.class), 0);

    3、定义notification:new Notification(icon, text, when).setLatestEventInfo(context, tiltel, text, pendingIntent);

      notification包括(具体见源代码):

        icon:显示在状态栏;

        可选的ticker-text:显示在状态栏的简单消息;

        下拉中的通知内容:默认是title、message;可自定义layout,使用满足RemoteView的控件,notification.contentIntent = pendingIntent

        PendingIntent:用户选中通知后发送该intent给Android处理;

        可选的sound、震动、led;

        可选的flag:FLAG_AUTO_CANCEL用户点击后自动消失;FLAG_INSISTENT重复sound;FLAG_ONGOING_EVENT;FLAG_NO_CLEAR不可清除;number通知的事件个数;iconLevel同LevelListDrawable在状态栏显示不同icon;

    4、发通知:nm.notify(ID, notification);

      ID,标识不同通知,cancel(id)主动销毁。

    5、更新通知:setLatestEventInfo(),notify(ID,not);

  • 相关阅读:
    BZOJ3509: [CodeChef] COUNTARI
    BZOJ3790: 神奇项链
    BZOJ3527: [Zjoi2014]力
    BZOJ2194: 快速傅立叶之二
    解题:BJOI 2006 狼抓兔子
    解题:SDOI 2017 数字表格
    解题:TJOI 2015 弦论
    解题:NOI 2016 优秀的拆分
    解题:AHOI2017/HNOI2017 礼物
    解题:洛谷2093 JZPFAR
  • 原文地址:https://www.cnblogs.com/toven/p/2659069.html
Copyright © 2011-2022 走看看