0

I need to use downloadRequest.setNotificationVisibility(Down loadManager.Request.VISIBILITY_HIDDEN); in my app which is min API 10 but the method is for API >=11.

This would be a simple comment on the question at DownloadManager.Request.setNotificationVisibility fails with jSecurityException: invalid value for visibility: 2 but then I'm yet to earn more reputation to comment on others posts.

Please guide how I can use the method in my case.

Community
  • 1
  • 1
Mwas
  • 153
  • 2
  • 6
  • 17

1 Answers1

0

You cannot use that method. It did not exist prior to API Level 11 in the Android SDK, nor did its associated permission.

You can download the file yourself, using OkHttp3, HttpURLConnection, etc. Then, you are in greater control over what notifications are displayed, if any.

Or, you can conditionally call that method on supported devices:

if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.HONEYCOMB) {
  downloadRequest.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN);
}
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Ok, I just thought there would be something like android.support.v4.... – Mwas Aug 14 '16 at 21:52
  • @Mwas: Google has not created a `DownloadManagerCompat` class. I am not certain why. Even if they had, the `setNotificationVisibility()` would not work on API Level 10 -- a library from Google cannot change that. All the library's edition of `setNotificationVisibility()` would do is what I have in the code snippet in my answer: conditionally forward the request on newer devices, and just ignore it on older ones. – CommonsWare Aug 14 '16 at 21:59