• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            xiaoguozi's Blog
            Pay it forword - 我并不覺的自豪,我所嘗試的事情都失敗了······習慣原本生活的人不容易改變,就算現狀很糟,他們也很難改變,在過程中,他們還是放棄了······他們一放棄,大家就都是輸家······讓愛傳出去,很困難,也無法預料,人們需要更細心的觀察別人,要隨時注意才能保護別人,因為他們未必知道自己要什么·····

            ?
            1
            2
            3
            4
            5
            6
            7
            8
            9
            10
            11
            12
            13
            14
            15
            16
            17
            18
            19
            20
            21
            22
            23
            24
            25
            26
            27
            28
            29
            30
            31
            32
            33
            34
            35
            36
            37
            38
            39
            40
            41
            42
            43
            44
            45
            46
            47
            48
            49
            50
            51
            52
            53
            54
            55
            56
            57
            58
            59
            60
            61
            62
            63
            64
            65
            66
            67
            68
            69
            70
            71
            72
            73
            74
            75
            76
            77
            78
            79
            80
            81
            82
            83
            84
            85
            86
            87
            88
            89
            90
            91
            92
            93
            94
            95
            96
            97
            98
            99
            100
            101
            102
            103
            NotificationManager 和Notification的使用總結(轉)
            文章分類:移動開發
            這 幾天一直在修改twigee的源代碼,其中一個要加入的功能是常駐Notification欄,以前寫的時候只能出現 在“通知”這一組中,想把它放在“正在運行”組中卻不知道怎么放,查了下官方文檔,找到了方法,在notification的flags字段中加一下 “FLAG_ONGOING_EVENT”就可以了。同時我也把Notification的使用方法給總結了一下。詳見下文:
            (1)、使用系統定義的Notification
            以下是使用示例代碼:
            //創建一個NotificationManager的引用
            String ns = Context.NOTIFICATION_SERVICE;
            NotificationManager mNotificationManager = (NotificationManager)getSystemService(ns);
            // 定義Notification的各種屬性
            int icon = R.drawable.icon; //通知圖標
            CharSequence tickerText = "Hello"; //狀態欄顯示的通知文本提示
            long when = System.currentTimeMillis(); //通知產生的時間,會在通知信息里顯示
            //用上面的屬性初始化 Nofification
            Notification notification = new Notification(icon,tickerText,when);
            /*
            * 添加聲音
            * notification.defaults |=Notification.DEFAULT_SOUND;
            * 或者使用以下幾種方式
            * notification.sound = Uri.parse("file:///sdcard/notification/ringer.mp3");
            * notification.sound = Uri.withAppendedPath(Audio.Media.INTERNAL_CONTENT_URI, "6");
            * 如果想要讓聲音持續重復直到用戶對通知做出反應,則可以在notification的flags字段增加"FLAG_INSISTENT"
            * 如果notification的defaults字段包括了"DEFAULT_SOUND"屬性,則這個屬性將覆蓋sound字段中定義的聲音
            */
            /*
            * 添加振動
            * notification.defaults |= Notification.DEFAULT_VIBRATE;
            * 或者可以定義自己的振動模式:
            * long[] vibrate = {0,100,200,300}; //0毫秒后開始振動,振動100毫秒后停止,再過200毫秒后再次振動300毫秒
            * notification.vibrate = vibrate;
            * long數組可以定義成想要的任何長度
            * 如果notification的defaults字段包括了"DEFAULT_VIBRATE",則這個屬性將覆蓋vibrate字段中定義的振動
            */
            /*
            * 添加LED燈提醒
            * notification.defaults |= Notification.DEFAULT_LIGHTS;
            * 或者可以自己的LED提醒模式:
            * notification.ledARGB = 0xff00ff00;
            * notification.ledOnMS = 300; //亮的時間
            * notification.ledOffMS = 1000; //滅的時間
            * notification.flags |= Notification.FLAG_SHOW_LIGHTS;
            */
            /*
            * 更多的特征屬性
            * notification.flags |= FLAG_AUTO_CANCEL; //在通知欄上點擊此通知后自動清除此通知
            * notification.flags |= FLAG_INSISTENT; //重復發出聲音,直到用戶響應此通知
            * notification.flags |= FLAG_ONGOING_EVENT; //將此通知放到通知欄的"Ongoing"即"正在運行"組中
            * notification.flags |= FLAG_NO_CLEAR; //表明在點擊了通知欄中的"清除通知"后,此通知不清除,
            * //經常與FLAG_ONGOING_EVENT一起使用
            * notification.number = 1; //number字段表示此通知代表的當前事件數量,它將覆蓋在狀態欄圖標的頂部
            * //如果要使用此字段,必須從1開始
            * notification.iconLevel = ; //
            */
            //設置通知的事件消息
            Context context = getApplicationContext(); //上下文
            CharSequence contentTitle = "My Notification"; //通知欄標題
            CharSequence contentText = "Hello World!"; //通知欄內容
            Intent notificationIntent = new Intent(this,Main.class); //點擊該通知后要跳轉的Activity
            PendingIntent contentIntent = PendingIntent.getActivity(this,0,notificationIntent,0);
            notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
            //把Notification傳遞給 NotificationManager
            mNotificationManager.notify(0,notification);
            如果想要更新一個通知,只需要在設置好notification之后,再次調用 setLatestEventInfo(),然后重新發送一次通知即可,即再次調用notify()。
            (2)、使用自定義的 Notification
            要 創建一個自定義的Notification,可以使用RemoteViews。要定義自己的擴展消息,首先 要初始化一個RemoteViews對象,然后將它傳遞給Notification的contentView字段,再把PendingIntent傳遞給 contentIntent字段。以下示例代碼是完整步驟:
            //1、創建一個自 定義的消息布局 view.xml
            <?xml version="1.0" encoding="utf-8"?>
            <LinearLayout xmlns:android="
            posted on 2012-04-05 02:34 小果子 閱讀(616) 評論(0)  編輯 收藏 引用 所屬分類: Android & Ios
            精品一区二区久久久久久久网站| 久久人人青草97香蕉| 亚洲香蕉网久久综合影视| 久久久久亚洲AV无码麻豆| 久久国产精品国语对白| 99久久国产宗和精品1上映| 国产成人精品久久综合 | 久久婷婷五月综合97色| 久久久久国产一级毛片高清版| 久久久久久久亚洲精品| 久久综合国产乱子伦精品免费| 精品国产91久久久久久久a | 99精品国产99久久久久久97| 97久久精品人人澡人人爽| 亚洲精品乱码久久久久久蜜桃图片 | 亚洲精品无码久久一线| 久久久久一级精品亚洲国产成人综合AV区| 欧美日韩精品久久免费| 久久久久99精品成人片三人毛片 | 国产精品99久久免费观看| 7777精品久久久大香线蕉| 中文精品久久久久人妻| 精品久久久久国产免费| 9191精品国产免费久久| 久久精品人成免费| 久久人人爽人人爽人人片AV不 | 久久久老熟女一区二区三区| 伊人 久久 精品| 日韩久久久久中文字幕人妻 | 久久久久无码国产精品不卡| 天天久久狠狠色综合| 久久99国产亚洲高清观看首页| 午夜精品久久久久久久久| 久久香综合精品久久伊人| 久久综合给久久狠狠97色| 国内精品久久久久影院日本| 久久精品国产亚洲av影院| 久久午夜电影网| 久久精品成人免费观看97| 色综合久久88色综合天天 | 18禁黄久久久AAA片|