0

내 응용 프로그램에 다운로드 알림이 있습니다. addAction() 메서드를 호출하여 NotificationCompat.Builder에 '취소'버튼을 추가했습니다. 하지만 Android O 기기에서는 버튼이 작동하지 않습니다. "취소"버튼을 누르면 아무 일도 일어나지 않습니다. 그러나 버튼을 PendingIntent이 Android O에서 작동하지 않습니다

Example Screenshot


O.

안드로이드 < 작업 내 Notification :

NotificationCompat.Builder notification = new NotificationCompat.Builder(context, channelId) 
      .setContentTitle(title) 
      .setSmallIcon(R.drawable.network_download) 
      .setContentText(contentText) 
      .setOngoing(true) 
      .setContentIntent(null) 
      .addExtras(idBundle) 
      .addAction(R.drawable.cancel, context.getString(R.string.cancel), getCancelPendingIntent(context, id)) 
      .setProgress(100, 30, true); 

PendingIntent :

또한
private PendingIntent getCancelPendingIntent(Context context, int id){ 
    return PendingIntent.getBroadcast(
      context, id, new Intent("CANCEL_DOWNLOAD").putExtra("id", id), PendingIntent.FLAG_UPDATE_CURRENT); 
} 

I NotificationReceiver 있습니다

Manifest 파일에서

나는이 :

<receiver 
     android:name="eu.warble.pjapp.util.NotificationsManager$NotificationReceiver" 
     android:exported="false"> 
     <intent-filter> 
      <action android:name="CANCEL_DOWNLOAD" /> 
     </intent-filter> 
</receiver> 

답변

3

결코 사용 암시 Intent을 명시 적 Intent 할 때. Android O는 매니 페스트 등록 수신기에서 암시적인 Intent 브로드 캐스트 수신을 금지하여이를 시행하는 데 도움이됩니다.

단계 # 1 :

단계 # 2 (또한 기본 값이 지금처럼 당신이 android:exported="false" 제거 할 수 있음을 의미하는) 당신의 <receiver>에서 <intent-filter>을 제거 new Intent(context, NotificationReceiver.class).putExtra("id", id)

new Intent("CANCEL_DOWNLOAD").putExtra("id", id) 교체
관련 문제