国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android消息通知欄的實現方法介紹

2020-04-11 12:07:42
字體:
來源:轉載
供稿:網友
背景知識:可以用Activity和Service來開始消息通知,兩者的區別在于一個是在前臺觸發,一個是后臺服務觸發。
要使用消息通知,必須要用到兩個類:NotificationManagerNotification,其他NotificationManager的初始化是用getSystemService方法,并且通過notify方法來向android系統發送消息欄通知和顯示。
效果 :

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

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

        //定義下拉通知欄時要展現的內容信息
        Context context = getApplicationContext();
        CharSequence contentTitle = "我的通知欄標展開標題";
        CharSequence contentText = "我的通知欄展開詳細內容";
        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);

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 平安县| 石楼县| 屏山县| 义乌市| 抚顺市| 赤峰市| 手游| 本溪| 柯坪县| 崇左市| 烟台市| 宁武县| 中江县| 乌兰察布市| 精河县| 恩施市| 乌海市| 海兴县| 崇明县| 江津市| 浑源县| 阳朔县| 平阴县| 航空| 乐东| 分宜县| 浦城县| 永和县| 海丰县| 东光县| 尚志市| 岳阳县| 宝应县| 嘉荫县| 蚌埠市| 辉县市| 正镶白旗| 青冈县| 井陉县| 余江县| 和平县|