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