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

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

 更新時(shí)間:2013年06月19日 11:34:25   作者:  
本篇文章是對(duì)Android消息通知欄的實(shí)現(xiàn)方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
背景知識(shí):可以用Activity和Service來開始消息通知,兩者的區(qū)別在于一個(gè)是在前臺(tái)觸發(fā),一個(gè)是后臺(tái)服務(wù)觸發(fā)。
要使用消息通知,必須要用到兩個(gè)類: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 = "我的通知欄標(biāo)題";
        long when = System.currentTimeMillis();
        Notification notification = new Notification(icon, tickerText, when);

        //定義下拉通知欄時(shí)要展現(xiàn)的內(nèi)容信息
        Context context = getApplicationContext();
        CharSequence contentTitle = "我的通知欄標(biāo)展開標(biāo)題";
        CharSequence contentText = "我的通知欄展開詳細(xì)內(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方法通知用戶生成標(biāo)題欄消息通知
        mNotificationManager.notify(1, notification);

相關(guān)文章

最新評(píng)論

正宁县| 永春县| 土默特左旗| 武功县| 赞皇县| 武义县| 东海县| 深圳市| 南和县| 凤凰县| 二连浩特市| 吉安县| 泗阳县| 云浮市| 福州市| 闵行区| 海盐县| 深水埗区| 乐业县| 建湖县| 定州市| 揭东县| 惠安县| 通河县| 崇明县| 汾西县| 颍上县| 莆田市| 行唐县| 合江县| 扎兰屯市| 山东| 扎囊县| 麻江县| 贵德县| 九寨沟县| 木里| 甘谷县| 辉南县| 修武县| 藁城市|