Android——通知 Notification

 

 

連接:http://jingyan.baidu.com/article/77b8dc7fde875a6175eab641.htmlhtml

        http://www.2cto.com/kf/201502/374946.htmljava

javaui

public void notification_onclick(View view){

        Resources res = Activitywenben.this.getResources();
        //1.獲取狀態欄消息管理器
        NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);

        //3.實現頁面跳轉,構建意圖
        Intent intent = new Intent(this,Activitybase.class);

        //4.獲取PendingIntent
        PendingIntent pendingIntent = PendingIntent.getActivity(this,1,intent,0);

        //2.構建消息  用Builder構建 方法鏈調用
        Notification nt = new Notification.Builder(this)

                .setSmallIcon(R.drawable.anniu2)
                .setContentTitle("這是一條消息通知")
                .setContentText("這是通知內容:點擊打開新的界面")
                .setContentIntent(pendingIntent)
                .setTicker("顯示在狀態欄中的信息")
                .setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.mm))
                .setAutoCancel(true)
                .setDefaults(Notification.DEFAULT_ALL)
                .build();

        //3.交給管理器發出消息
        manager.notify(0,nt);
    }
}

相關文章
相關標籤/搜索