Android 簡單 通知欄 Notification

Notificaiton狀態通知欄:主要是用在消息的提醒,類似於QQ,微信信息來的時候在通知欄彈出一個通知。可以有點擊效果。

首先我們先獲得通知欄的服務實例。

NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
這個服務實例對象負責發通知,清除通知

然後我們就進行通知欄構造器的構造

NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.wsy2)
                .setContentTitle(getResources().getString(R.string.app_name))
                .setContentText("彈出的信息文本")
                .setOngoing(true)
                .setDefaults(Notification.DEFAULT_VIBRATE);
接着我們可以使用意圖的方式來進行一些操作(如跳轉到那個Activity裏面去)

Intent backIntent = new Intent(this, ScreenRecordActivity.class);
        backIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
最後通過PendingIntent(和Intent略有不同,它可以設置執行次數,主要用於遠程服務通信、鬧鈴、通知、啓動器、短信中,在一般情況下用的比較少。)
PendingIntent pendingIntent = PendingIntent.getActivity(this, PENDING_REQUEST_CODE, backIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        builder.setContentIntent(pendingIntent);
        mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        mNotificationManager.notify(NOTIFICATION_ID, builder.build());



深入瞭解到http://blog.csdn.net/vipzjyno1/article/details/25248021/


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章