1. 程式人生 > >Android訊息推送接收後,通知欄的顯示

Android訊息推送接收後,通知欄的顯示

訊息推送接收到後,顯示通知欄

    public static void showNotifictionIcon(Context context) {
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
        Intent intent = new Intent(context, XXXActivity.class);//將要跳轉的介面
        //Intent intent = new Intent();//只顯示通知,無頁面跳轉
        builder.setAutoCancel(true
);//點選後消失 builder.setSmallIcon(R.drawable.app_icon);//設定通知欄訊息標題的頭像 builder.setDefaults(NotificationCompat.DEFAULT_SOUND);//設定通知鈴聲 builder.setTicker("狀態列顯示的文字"); builder.setContentTitle("標題"); builder.setContentText("通知內容"); //利用PendingIntent來包裝我們的intent物件,使其延遲跳轉
PendingIntent intentPend = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); builder.setContentIntent(intentPend); NotificationManager manager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE); manager.notify(0
, builder.build()); }