download manager - java.lang.NoSuchMethodError: android.app.DownloadManager$Request.setNotificationVisibility -
trying use downloadmanager so
downloadmanager.request request = new downloadmanager.request(uri) .setallowednetworktypes(downloadmanager.request.network_mobile) .setallowednetworktypes(downloadmanager.request.network_wifi) .setallowedoverroaming(true) .setdestinationinexternalfilesdir(this, null,string.valueof(mpathandfolder)) .setvisibleindownloadsui(false) .setnotificationvisibility(downloadmanager.request.visibility_hidden); long downloadid = downloadmanager.enqueue(request);
added following permission in android manifest
<uses-permission android:name="android.permission.download_without_notification"/>
getting following error @ runtime
java.lang.nosuchmethoderror: android.app.downloadmanager$request.setnotificationvisibility
why error? how make downloadmanager work?
do need use 2 separate downloadmanager.request 1 api 9 , api 11?
no, need use java guard block:
downloadmanager.request request = new downloadmanager.request(uri) .setallowednetworktypes(downloadmanager.request.network_mobile) .setallowednetworktypes(downloadmanager.request.network_wifi) .setallowedoverroaming(true) .setdestinationinexternalfilesdir(this, null,string.valueof(mpathandfolder)) .setvisibleindownloadsui(false); if (build.version.sdk_int>=build.version_codes.honeycomb) { request.setnotificationvisibility(downloadmanager.request.visibility_hidden); }
and, have settle fact download visible api level 9 , 10 devices.
Comments
Post a Comment