본문 바로가기
블로그 이미지

방문해 주셔서 감사합니다! 항상 행복하세요!

  
   - 문의사항은 메일 또는 댓글로 언제든 연락주세요.
   - "해줘","답 내놔" 같은 질문은 답변드리지 않습니다.
   - 메일주소 : lts06069@naver.com


기타/Android

안드로이드 8.0부터 Notifications 사용

야근없는 행복한 삶을 위해 ~
by 마샤와 곰 2019. 4. 30.

 

 

안드로이드8.0에서 가장 짜증났던것은, 
기존의 Notifications와 벳지카운터 메소드등등..
해당기능 사용법이 기존방식과 완전히 틀려졌다는 것이다
즉, 6.0이나 7.0이하에서 동작하는 기법이 8.0 이상부터는..안된다는것이다..

그리고..이클립스로 개발한다면 거의 포기하는게 나을 듯 싶다..
왠만하면 안드로이드 스튜디오로..

해당 구현방법 예제이다

int keyNumber = new Random().nextInt(2147483600); // notification 작업번호 지정, 작업번호가 같으면 덮어씌우기 처럼 되어 버린다.  

PendingIntent pendingIntent = PendingIntent.getActivity(ctx.getApplicationContext(),0, new Intent() ,PendingIntent.FLAG_ONE_SHOT); 
//실행하고자 하는 액티비티가 있으면 new Intent를 구현한다.
NotificationManager notificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
String channelId = "내가 원하는 체널ID, 문자열"; //기본 값, 오레오 이하 버전을 위해서

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { //오레오 이상
    NotificationChannel channel = new NotificationChannel("그룹","채널", NotificationManager.IMPORTANCE_DEFAULT);
    //그룹 및 채널은 내가 원하는 고유 키값으로 넣으면 된다.
    channel.setShowBadge(true);
    notificationManager.createNotificationChannel(channel);
    channelId = channel.getId();
}
Notification notification = new NotificationCompat.Builder(ctx.getApplicationContext(), channelId)
    .setContentTitle(title)
    .setContentText(pushMsg)
    .setSmallIcon(R.drawable.ic_launcher_background)
    .setNumber(badgeCount)
    .setContentIntent(pendingIntent)
    .setAutoCancel(true)
    .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
    .setVibrate(new long[]{0, 500, 100})
    .build();
notificationManager.notify(keyNumber, notification);

 

반응형

'기타 > Android' 카테고리의 다른 글

플레이 스토어 일시 정지  (0) 2019.04.30
안드로이드 앱 아이콘 변경  (0) 2019.04.30
안드로이드 doze모드 만들기  (0) 2019.04.30
안드로이드 Doze모드  (0) 2019.04.30
안드로이드 Badge Count  (0) 2019.04.29
* 위 에니메이션은 Html의 캔버스(canvas)기반으로 동작하는 기능 입니다. Html 캔버스 튜토리얼 도 한번 살펴보세요~ :)
* 직접 만든 Html 캔버스 애니메이션 도 한번 살펴보세요~ :)

댓글