Android下载管理器

时间:2016-09-27 18:07:31

标签: java android

我为我的android下载管理器使用了一个自定义库 https://github.com/smanikandan14/ThinDownloadManager

好像我有问题了 onProgress方法

我尝试在onProgress方法中更改textview的文本,但我没有改变...但如果我尝试更改ondownloadcomplete中的文本...它的工作原理 我认为这是一些线程问题

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    downloadbutton=(Button)findViewById(R.id.button_download);
    textView=(TextView)findViewById(R.id.textview);
    Runtime.getRuntime().availableProcessors();

    Uri downloadUri = Uri.parse("http://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4");
    Uri destinationUri = Uri.parse(this.getExternalCacheDir().toString()+"/test.mp4");
    final   DownloadRequest downloadRequest = new DownloadRequest(downloadUri)
            .addCustomHeader("Auth-Token", "YourTokenApiKey")
            .setRetryPolicy(new DefaultRetryPolicy())
            .setDestinationURI(destinationUri).setPriority(DownloadRequest.Priority.HIGH)
            .setDownloadListener(new DownloadStatusListener() {
                @Override
                public void onDownloadComplete(int id) {
                    textView.setText("complete");
                }

                @Override
                public void onDownloadFailed(int id, int errorCode, String errorMessage) {

                }

                @Override
                public void onProgress(int id, long totalBytes, long downlaodedBytes, int progress) {

                }


            });

    downloadbutton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
             ThinDownloadManager downloadManager;
            downloadManager = new ThinDownloadManager();
            int downloadId = downloadManager.add(downloadRequest);
        }
    });
}

1 个答案:

答案 0 :(得分:0)

我在onProgress方法中添加了一个UIthread,它解决了这个问题。