2012-03-21 10 views
0

DownloadManagerに失敗初期化が2.3 SDKですが、私は< 2.3デバイスでそれを使用したいので、私はソースからのコードをコピーしますが、カスタムDownloadManagerが、それはシステムの

が、私はそれを呼び出す:

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を投稿します

答えて

1

ダウンロードマネージャを<に使用することはできません2.3 APIレベルが<のデバイスでgetSystemServiceを呼び出すと、nullが返されます。それはなぜNULLポインタの例外を取得しているのですか?

関連する問題