티스토리 뷰

IT 생활

안드로이드 상단 알림_Notification

개구리뒷다리 2017. 2. 27. 17:29

안드로이드 개발시 상단에 밑으로 쭉 내리면 나오는 영역에 알림을 직접 나타나게 할 수 있습니다. NotificationManager를 이용하면 됩니다. 소스는 아래에 첨부하였습니다. 참고하시기 바랍니다.


 NotificationManager nm = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
        NotificationCompat.Builder nc = new NotificationCompat.Builder(getApplicationContext());
        Intent i = new Intent(this, 선택하면 이동할 페이지);

        i.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS|Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pi = PendingIntent.getActivity(context, id, i, PendingIntent.FLAG_UPDATE_CURRENT|PendingIntent.FLAG_CANCEL_CURRENT);

        nc.setContentTitle("타이틀");
        nc.setContentText("메시지 내용");
        nc.setSmallIcon(R.mipmap.ic_launcher); // 로고
        nc.setAutoCancel(true); // 선택시 자동 삭제

        nc.setDefaults(Notification.DEFAULT_ALL); // 진동, 소리 같이 울리도록

        nc.setContentIntent(pi); // 인텐트
        nc.setNumber(); // 표시 숫자
        nc.build();

        nm.notify(id, nc.build()); // 알림 실행

 

이상 안드로이드 상단 알림_Notification에 대해 알아보았습니다.

댓글
최근에 올라온 글
최근에 달린 댓글
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Total
Today
Yesterday