2017-10-26 5 views
2

상단에 Android 알림을 표시하는 방법은 무엇입니까? setPriority(Notification.PRIORITY_MAX)Android Notification.PRIORITY_MAX이 (가) 사용 중지되었습니다. 상단에 알림을 표시하는 대신 무엇을 사용할 수 있습니까?

Notification.PRIORITY_MAX는 (는) 더 이상 사용되지 않습니다. 대체 무엇입니까?

NotificationCompat.Builder builder = new NotificationCompat.Builder(context) 
       .setContentIntent(pendingIntent) 
       .setSmallIcon(R.mipmap.ic_launcher) 
       .setContentTitle("Notification Title") 
       .setContentText("Notification Text") 
       .setPriority(Notification.PRIORITY_MAX) 
       .setAutoCancel(true); 
+0

"더 이상 안드로이드 알림 표시"권한이 없습니다. – CommonsWare

+0

@CommonsWare에서는 알림 채널 자체에 IMPORTANCE_MAX를 설정해야합니다. 내 대답을 확인하십시오. – Aks4125

답변

2

안드로이드 O에는 Notification channels의 소개가있었습니다. 특히 채널을 constructor으로 정의하십시오. 문서화에서는 중요도 개념을 볼 수 있으며 이것이 우선 순위를 대체합니다.

0

PRIORITY_MAX 이 상수는 API 레벨 26에서 사용되지 않습니다. 대신 IMPORTANCE_HIGH을 사용하십시오.

PRIORITY_MAX

INT PRIORITY_MAX

이 정수는 26 사용 IMPORTANCE_HIGH 대신 API 레벨을 사용합니다.

사용자의 즉각적인주의 또는 입력이 필요한 응용 프로그램의 가장 중요한 항목에 우선 순위가 가장 높습니다.

상수 값 : 2 (0x00000002)

// create ios channel 
     NotificationChannel iosChannel = new NotificationChannel(IOS_CHANNEL_ID, 
       IOS_CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH); 
     iosChannel.enableLights(true); 
     iosChannel.enableVibration(true); 
     iosChannel.setLightColor(Color.GRAY); 
     iosChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC); 
     getManager().createNotificationChannel(iosChannel); 

https://developer.android.com/reference/android/app/Notification.html#PRIORITY_MIN

+0

질문에 집중하십시오 (PRIORITY_MAX). * 할 일을 설명해 주셔서 감사 드리며, 어떻게해야하는지 (중요성을 강조하는 방법)를 말씀해 주셔서 감사합니다. –

-1

에게 오직 세 가지 단계를 최대로 설정하는 모든 안드로이드 버전에 대한 코드 작업 안드로이드 O 알림

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, "CHANNEL_ID") 

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 
       CharSequence name = "Hello";// The user-visible name of the channel. 
       int importance = NotificationManager.IMPORTANCE_HIGH; 
       NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, importance); 
       mNotificationManager.createNotificationChannel(mChannel); 
      } 




mNotificationManager.notify(notificationId, notificationBuilder.build()); 
+0

답변에서 코드의 서식을 지정하는 방법을 스스로 가르쳐주십시오. 구글 그것. –

0

위해 따라야 할 우선 순위.

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
    String NOTIFICATION_CHANNEL_ID = "my_channel_id_01"; 

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 
    NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "My Notifications", NotificationManager.IMPORTANCE_MAX); 

    // Configure the notification channel. 
    notificationChannel.setDescription("Channel description"); 
    notificationChannel.enableLights(true); 
    notificationChannel.setLightColor(Color.RED); 
    notificationChannel.setVibrationPattern(new long[]{0, 1000, 500, 1000}); 
    notificationChannel.enableVibration(true); 
    notificationManager.createNotificationChannel(notificationChannel); 
} 


NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID); 

notificationBuilder.setAutoCancel(true) 
     .setDefaults(Notification.DEFAULT_ALL) 
     .setWhen(System.currentTimeMillis()) 
     .setSmallIcon(R.drawable.ic_launcher) 
     .setTicker("Hearty365") 
     .setPriority(Notification.PRIORITY_MAX) 
     .setContentTitle("Default notification") 
     .setContentText("Lorem ipsum dolor sit amet, consectetur adipiscing elit.") 
     .setContentInfo("Info"); 

notificationManager.notify(/*notification id*/1, notificationBuilder.build());