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

notification channel 적용

0 추천
안녕하세요

notification channel 적용으로 문의 드립니다.

app이 실행하지 않을 때 서버로부터 팝업 메시지를 받을 수 없고, 알림음이나 진동 또한 없습니다. 따라서 notification channel을 적용하려고 하는데

NotificationCompat.Builder builder = new NotificationCompat.Builder(this, chanelId);

부분에서 NotificationCompat.Builder에 두 개의 인자를 적용할 수가 없습니다 ㅠ

this 또는 getApplicationContext() 한개만 넣었을 때는 오류가 발생하지는 않지만 똑같이 app이 실행하지 않을 때 서버로부터 팝업 메시지를 받을 수 없고, 알림음이나 진동 또한 없습니다.

의심 가는 부분은 NotificationCompat.Builder에 ChaneId를 작성해야할 것 같은데 작성하면 오류가 납니다. 오류 내용은 actual and formal argument list differ in length 입니다.

도움 부탁드립니다 ㅠ
익명사용자 님이 2019년 7월 15일 질문

1개의 답변

0 추천
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.foreground);

NotificationCompat.Builder builder;

if (Build.VERSION.SDK_INT >= 26) {
    String CHANNEL_ID = "TEST_CHANNEL";
    NotificationChannel channel = new NotificationChannel(CHANNEL_ID, "TEST Service Channel", NotificationManager.IMPORTANCE_DEFAULT);

    ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).createNotificationChannel(channel);

    builder = new NotificationCompat.Builder(this, CHANNEL_ID);
} else {
    builder = new NotificationCompat.Builder(this);
}
builder.setSmallIcon(R.mipmap.ic_launcher)
        .setContent(remoteViews)
        .setContentIntent(pendingIntent);

startForeground(1, builder.build());
평범 (3,560 포인트) 님이 2019년 7월 25일 답변
...