How can I wait until DownloadManager is complete?

后端 未结 2 1595
忘了有多久
忘了有多久 2021-01-15 09:59

This is the code I\'m currently using

                String iosjiUrl = \"http://modapps.com/NotoCoji.ttf\";
                DownloadManager.Request request          


        
2条回答
  •  渐次进展
    2021-01-15 10:35

    A Broadcast intent action sent by the download manager when a download completes so you need to register a receiver for when the download is complete:
    
    To register receiver
    
    registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
    
    and a BroadcastReciever handler
    
    BroadcastReceiver onComplete=new BroadcastReceiver() {
        public void onReceive(Context ctxt, Intent intent) {
            // your code
        }
    };
    
    You can also create AsyncTask to handle the downloading of big files
    
    Create a download dialog of some sort to display downloading in notification area and than handle the opening of the file:
    
    protected void openFile(String fileName) {
        Intent install = new Intent(Intent.ACTION_VIEW);
        install.setDataAndType(Uri.fromFile(new File(fileName)),"MIME-TYPE");
        startActivity(install);
    }
    
    you can also check the sample link
    sample

提交回复
热议问题