0
下载管理器是SDK 2.3,我想在< 2.3设备上使用它,所以我复制从源代码,但自定义下载管理器,但初始化它无法通过系统的
我把它叫做:
public long startDownload(Uri downloadUri, boolean onlyWifi)
{
DownloadManager.Request request = new DownloadManager.Request(downloadUri);
request.setTitle("Test Download File"); //
request.setDescription("App Name");
//request.setDestinationInExternalFilesDir(context, dirType, subPath);
request.setDestinationInExternalPublicDir("/sdcard", "test.mp4");
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
final DownloadManager dManager = (DownloadManager)TestDownloadManager.this.getSystemService("download");
return dManager.enqueue(request);
}
但它给我:
03-21 06:57:21.181: ERROR/AndroidRuntime(420): Caused by: java.lang.NullPointerException
03-21 06:57:21.181: ERROR/AndroidRuntime(420): at com.test.DownloadManager.TestDownloadManager.startDownload(TestDownloadManager.java:32)
03-21 06:57:21.181: ERROR/AndroidRuntime(420): at com.test.DownloadManager.TestDownloadManager.onCreate(TestDownloadManager.java:16)
03-21 06:57:21.181: ERROR/AndroidRuntime(420): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
我在
发布download.java