Search code examples
javaandroidpermissionsandroid-download-manager

Download Manager Request setNotificationVisiblity


Reference: https://developer.android.com/reference/android/app/DownloadManager.Request

setNotificationVisibility(int visiblity)

Control whether a system notification is posted by the download manager while this download is running or when it is completed. If enabled, the download manager posts notifications about downloads through the system NotificationManager. By default, a notification is shown only when the download is in progress.

It can take the following values: VISIBILITY_HIDDEN, VISIBILITY_VISIBLE, VISIBILITY_VISIBLE_NOTIFY_COMPLETED.

If set to VISIBILITY_HIDDEN, this requires the permission android.permission.DOWNLOAD_WITHOUT_NOTIFICATION.

So I want to setNotificationVisiblity to VISIBLITY_HIDDEN. According to docs I need to set the permission in AndroidManifest.xml. Where is the permission?

I can't find permission android.permission.DOWNLOAD_WITHOUT_NOTIFICATION in Manifest.permission

Reference: https://developer.android.com/reference/android/Manifest.permission

Has this permission been removed from Android? If I set downaloadReq.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN) without permission it throws a SecurityException. So what can I do?


Solution

  • Your permission is indeed missing in the AndroidManifest.xml file.

    Just add the following line:

    <uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION"/>