亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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ā)送消息欄通知和顯示。
效果 :

代碼:
復制代碼 代碼如下:

//消息通知欄
        //定義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)文章

最新評論