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

sdk 버전 26에서의 알림 푸쉬 동작관련 질문입니다.

0 추천

기존에 sdk 버전 22로 스케줄을 입력하고 해당 스케줄 시간에 알림이 오는 어플을

개발하고 있었습니다. 버전 22의 경우 manifest에서 

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
public void onButtonClicked(View v){
    NotificationManager notificationManager= (NotificationManager)MainActivity.this.getSystemService(MainActivity.this.NOTIFICATION_SERVICE);
    Intent intent1 = new Intent(MainActivity.this.getApplicationContext(),MainActivity.class);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext());
    intent1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP| Intent.FLAG_ACTIVITY_CLEAR_TOP);

    PendingIntent pendingNotificationIntent = PendingIntent.getActivity( MainActivity.this,0, intent1, FLAG_UPDATE_CURRENT);

    builder.setSmallIcon(R.drawable.on).setTicker("HETT").setWhen(System.currentTimeMillis()).setNumber(1).setContentTitle("푸쉬 제목").setContentText("푸쉬내용").setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE).setContentIntent(pendingNotificationIntent).setAutoCancel(true).setOngoing(true);

    notificationManager.notify(1, builder.build());

}

위의 3가지 권한만 사용하면 Notification를 동작하는데 아무 이상없었는데

26버전의 경우 알림 기능이 실행되지 않습니다.

추가적으로 설정해줘야하는 권한이 있을까요?

밑의 코드는 다른분 블로그에서 받아온 코드인데요 실행해보니 22버전에서는 알림이 동작하는데

23이상에서는 동작하지 않네요

Ironkey (140 포인트) 님이 2017년 7월 6일 질문
Ironkey님이 2017년 7월 6일 수정

1개의 답변

0 추천
마쉬멜로 부터는 runtime permission을 주셔야 합니다.

https://news.realm.io/kr/news/android-marshmellow-permission/
익명사용자 님이 2017년 7월 6일 답변
답변 감사합니다. 일반권한은 runtime permission이 필요없다고 알고 있는데,, 위험권한 뿐 아니라 일반권한도 runtime permission을 줘야하는 건가요?
혹시 줘야한다면 INTERNET, VIBRATE, WAKE_LOCK 세가지 모두 줘야하나요?
혹시 해서 runtime permission 다 줘봤는데 안되네요..
권한문제가 아닌것 같습니다... 마시멜로 이전버전에서 Manifest에 권한을 주지 않아도 단순 알림기능은 가능하네요..
아 권한 이슈라 해서 제가 잘 못 답변 드렸네요..
doze 모드가 추가 되서 안될 수 있으니 확인 해 보세요..
https://developers-kr.googleblog.com/2015/10/gcmonandroid-doze.html
https://devtalk.kakao.com/t/gcm/15478
해결하진 못했지만 답변해주셔서 감사합니다 ㅠㅠ
저도 지금 이것때문에 고민중이네 혹시 해결 하셨으면 해결 방법 공유 부탁드릴게요~
...