I have implemented DownloadManager in my application. I knew that the DownloadManager requires minimum sdkVersion 9. But my application should have minimum sdkVersion of 8. I have used AsyncTask for download in the sdkVersion 8. For version above 9, am using DownloadManager. Below is my way of implemtation.
if (Build.VERSION.SDK_INT >= 9) {
android.app.DownloadManager downloadManager
= (android.app.DownloadManager) getActivity().getSystemService(Context.DOWNLOAD_SERVICE);
Uri downloadUri = Uri.parse(url.replace(" ", ""));
android.app.DownloadManager.Request request = new android.app.DownloadManager.Request(downloadUri);
request.setVisibleInDownloadsUi(true);
downloadManager.enqueue(request);
Toast.makeText(getActivity(), "Download started... Please find the downloading process in notificaion bar.", Toast.LENGTH_LONG).show();
}
else if (Build.VERSION.SDK_INT == 8) {
//AysncTask for downloading...
}
When I run this code in Gingerbread and above DownloadManager works fine. If I run this code in Froyo, application throws ClassNotFoundException. I don't know why this happens, because I am checking the Build version and DownloadManager should work only if the device version above 9. Error in Froyo happens duo to implementation of DownloadManager. When I run application in Froyo, AynceTask should start, but application throws ClassNotFoundException before Download action is performed. If any has faced this, please provide some solution regarding this.
EDIT: I couldn't find which line.. but when I open an activity with this code in Froyo, I get ClassNotFoundException.