안드로이드 알림 채널 이름이 바뀌지 않습니다.
조회수 442회
안드로이드 8.0부터 생긴 알림 채널의 이름이 "Miscellaneous"에서 제가 설정한 이름으로 바뀌지 않습니다. 아래는 제가 만든 알림을 처리하는 클래스입니다.
public class MyFirebaseMessagingService extends FirebaseMessagingService {
final String TAG = "FCM Service";
@Override
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
// Handle FCM messages here.
Log.d(TAG, "From: " + remoteMessage.getFrom());
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
sendNotification(remoteMessage);
}
}
@Override
public void onNewToken(@NonNull String token) {
Log.d(TAG, "Refreshed token: " + token);
}
private void sendNotification(RemoteMessage remoteMessage) {
String title = remoteMessage.getData().get("title");
String message = remoteMessage.getData().get("message");
String channelId = "version";
String channelTitle = "New version";
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.drawable.ic_bookmark_border_list)
.setContentTitle(title)
.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSoundUri);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// Make notification channel
NotificationChannel channel = new NotificationChannel(channelId, channelTitle,
NotificationManager.IMPORTANCE_HIGH);
channel.setDescription("새 버전이 있을 때마다 알려줍니다.");
channel.enableLights(true);
channel.setLightColor(Color.GREEN);
channel.enableVibration(true);
channel.setVibrationPattern(new long[]{100, 200, 100, 200});
channel.setName("새 버전");
channel.setShowBadge(true);
Objects.requireNonNull(notificationManager).createNotificationChannel(channel);
}
Objects.requireNonNull(notificationManager).notify(0, notificationBuilder.build());
}
}
다들 새해 복 많이 받으시고 벌써 연휴 마지막 날이네요 ㅠ 화이팅!!
-
(•́ ✖ •̀)
알 수 없는 사용자
댓글 입력