마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

안드로이드 Notification 문의 [closed]

0 추천

안드로이드 8.0이후 부터 Notification에 채널ID를 추가해줘야한다고 해줬는데 

안드로이드 8.0에서는 알림 유형 - 사용 안함 으로 되어 있고, 8.1은 알림 유형 - 소리 없음 으로 되어

8.0은 안 뜨고, 8.1은 뜹니다.

채널ID를 부여했는데도 왜 이렇죠??

커스텀 NOTIFICATION을 사용하였습니다.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
    startMyOwnForeground();
}else {
    startForeground(NOTIFICATION_ID, notification);
}
@TargetApi(Build.VERSION_CODES.O)
private void startMyOwnForeground(){
    String NOTIFICATION_CHANNEL_ID = "company.sensor.valuesensor";
    String channelName = "Service";
    NotificationChannel chan = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_NONE);
    chan.setLightColor(Color.BLUE);
    chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
    NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    assert manager != null;
    manager.createNotificationChannel(chan);

    Intent notiintent = new Intent(this, MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notiintent, PendingIntent.FLAG_UPDATE_CURRENT);

    Intent fininotiintent = new Intent(this, ServiceClass.class);
    fininotiintent.putExtra("finish_all", "finish_all");
    PendingIntent pfinishIntent = PendingIntent.getService(this, 0, fininotiintent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    Notification notification;
    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification_layout);
        contentView.setImageViewResource(R.id.image, R.mipmap.ic_launcher);
        contentView.setTextViewText(R.id.title, getResources().getString(R.string.noti_title));
        contentView.setTextViewText(R.id.text, getResources().getString(R.string.noti_content));
        contentView.setOnClickPendingIntent(R.id.finish_button, pfinishIntent);

        notification = new Notification.Builder(this)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContent(contentView)
                .setContentIntent(pendingIntent)
                .setPriority(Notification.PRIORITY_MAX)
                .setOngoing(true)
                .setChannelId(NOTIFICATION_CHANNEL_ID)
                .build();
   
    startForeground(NOTIFICATION_ID1, notification);
}
질문을 종료한 이유: 자체 해결
쿠쿠부다스 (6,470 포인트) 님이 2019년 3월 25일 질문
쿠쿠부다스님이 2019년 3월 25일 closed

1개의 답변

0 추천

아래와 같이 변경하니 잘되네요...

이유는 모르겠습니다...

NotificationChannel chan = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_LOW);
쿠쿠부다스 (6,470 포인트) 님이 2019년 3월 25일 답변
...