最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android消息通知欄的實現(xiàn)方法介紹

 更新時間:2013年06月19日 11:34:25   作者:  
本篇文章是對Android消息通知欄的實現(xiàn)方法進行了詳細的分析介紹,需要的朋友參考下
背景知識:可以用Activity和Service來開始消息通知,兩者的區(qū)別在于一個是在前臺觸發(fā),一個是后臺服務(wù)觸發(fā)。
要使用消息通知,必須要用到兩個類:NotificationManagerNotification,其他NotificationManager的初始化是用getSystemService方法,并且通過notify方法來向android系統(tǒng)發(fā)送消息欄通知和顯示。
效果 :

代碼:
復(fù)制代碼 代碼如下:

//消息通知欄
        //定義NotificationManager
        String ns = Context.NOTIFICATION_SERVICE;
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
        //定義通知欄展現(xiàn)的內(nèi)容信息
        int icon = R.drawable.icon;
        CharSequence tickerText = "我的通知欄標題";
        long when = System.currentTimeMillis();
        Notification notification = new Notification(icon, tickerText, when);

        //定義下拉通知欄時要展現(xiàn)的內(nèi)容信息
        Context context = getApplicationContext();
        CharSequence contentTitle = "我的通知欄標展開標題";
        CharSequence contentText = "我的通知欄展開詳細內(nèi)容";
        Intent notificationIntent = new Intent(this, BootStartDemo.class);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                notificationIntent, 0);
        notification.setLatestEventInfo(context, contentTitle, contentText,
                contentIntent);

        //用mNotificationManager的notify方法通知用戶生成標題欄消息通知
        mNotificationManager.notify(1, notification);

相關(guān)文章

最新評論

左贡县| 潼关县| 湖南省| 安徽省| 攀枝花市| 昌图县| 杭锦后旗| 鸡泽县| 黔东| 通州区| 阿鲁科尔沁旗| 崇礼县| 壤塘县| 孟州市| 开鲁县| 娱乐| 尼勒克县| 吉木萨尔县| 女性| 赣州市| 积石山| 灵川县| 策勒县| 安阳县| 德令哈市| 蕉岭县| 洪洞县| 鄄城县| 凤山市| 南宫市| 延寿县| 治县。| 邛崃市| 行唐县| 河曲县| 南通市| 苍梧县| 台北市| 临夏市| 霍林郭勒市| 成都市|