如何使用下载管理器逐个下载45个视频?

时间:2015-03-30 14:49:32

标签: android

无法使用下载管理器逐个下载45个视频。

错误:

03-30 19:47:59.240: E/AndroidRuntime(398): FATAL EXCEPTION: Timer-0
03-30 19:47:59.240: E/AndroidRuntime(398): Process: com.emedsim.falckclassroom, PID: 398
03-30 19:47:59.240: E/AndroidRuntime(398): java.lang.IllegalStateException: attempt to re-open an already-closed object: /data/user/0/com.android.providers.downloads/databases/downloads.db {5f5d4b50}
03-30 19:47:59.240: E/AndroidRuntime(398):  at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:55)
03-30 19:47:59.240: E/AndroidRuntime(398):  at android.database.CursorWindow.getLong(CursorWindow.java:509)
03-30 19:47:59.240: E/AndroidRuntime(398):  at android.database.AbstractWindowedCursor.getLong(AbstractWindowedCursor.java:75)
03-30 19:47:59.240: E/AndroidRuntime(398):  at android.database.CursorWrapper.getLong(CursorWrapper.java:106)
03-30 19:47:59.240: E/AndroidRuntime(398):  at android.database.CursorWrapper.getLong(CursorWrapper.java:106)
03-30 19:47:59.240: E/AndroidRuntime(398):  at android.app.DownloadManager$CursorTranslator.getLong(DownloadManager.java:1308)
03-30 19:47:59.240: E/AndroidRuntime(398):  at com.emedsim.falckclassroom.activities.MyCourse$3.run(MyCourse.java:409)
03-30 19:47:59.240: E/AndroidRuntime(398):  at java.util.Timer$TimerImpl.run(Timer.java:284)

这是附加代码:

public void test(){

        String temp = stockArr[x];
        subString = temp.substring(temp.lastIndexOf("/") + 1);
        String compUrl = filepath+course_name+"/section"+stockArr[x];
        Download_Uri = Uri.parse(compUrl);
        request = new Request(Download_Uri);
        request.setDestinationInExternalFilesDir(getActivity(), course_name,subString)
        .setNotificationVisibility(Request.VISIBILITY_HIDDEN)
        .setVisibleInDownloadsUi(false);
        Const.downloadId = Const.manager.enqueue(request);
        Const.myTimer = new Timer();
        Const.myTimer.schedule(new TimerTask() {
                @SuppressLint("NewApi") @Override
                    public void run() {
                            DownloadManager.Query q = new DownloadManager.Query();
                            q.setFilterById(Const.downloadId);
                            Const.cursor = Const.manager.query(q);
                                if(Const.cursor.moveToFirst()){
                                    bytes_downloaded = Const.cursor.getLong(Const.cursor.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR));
                                    bytes_total = Const.cursor.getLong(Const.cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES));
                                    try {
                                        dl_progress = (bytes_downloaded * 100)/bytes_total;
                                        //checkStatus(Const.cursor);
                                    } catch(ArithmeticException a){
                                            checkStatus(Const.cursor);
                                            boolean mbool = false;
                                            txtdownload_all.setChecked(mbool);
                                        Const.myTimer.cancel();
                                    }
                                Const.cursor.close();
                                    Log.d("dl_progress-->",""+dl_progress);
                                    if(bytes_downloaded == bytes_total){
                                        if(stockArr.length == x){
                                            Intent i = new Intent(getActivity(), SplitScreenMenu.class);
                                            startActivity(i);
                                        }else{
                                            int newthumb = fm.newthumb(getActivity(), course_name,subString);
                                            if(newthumb == 1){
                                                try {
                                                    int mineFile = fm.moveFileTointernal(getActivity(), subString, course_name);
                                                    if(mineFile == 1){
                                                        x++;
                                                        count++;
                                                         ((Activity) getActivity()).runOnUiThread(new Runnable(){
                                                           @Override
                                                          public void run(){
                                                            downloadCount = (TextView) view.findViewById(R.id.txtdownloadcount);
                                                            downloadCount.setText("Downloaded "+downloaded+" of "+total_video);
                                                            Log.d("",""+"Downloaded "+downloaded+" of "+total_video);
                                                           }
                                                         });
                                                        test();
                                                    }
                                                } catch (IOException e) {
                                                    // TODO Auto-generated catch block
                                                    e.printStackTrace();
                                                }
                                            }
                                        }
                                    }

                                }
                            }

            }, 0, 1000);
}

请告诉我错误的地方。

0 个答案:

没有答案