这是我正在使用的代码

                String iosjiUrl = "http://modapps.com/NotoCoji.ttf";
                DownloadManager.Request request = new DownloadManager.Request(Uri.parse(iosjiUrl));
                request.setDescription("Sscrition");
                request.setTitle("Somle");
// in order for this if to run, you must use the android 3.2 to compile your app
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                    request.allowScanningByMediaScanner();
                    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
                }
                request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "NotoColorji.ttf");

// get download service and enqueue file
                DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);

                manager.enqueue(request);

我找不到办法等到文件被下载。
我也试着弄清楚如何进行异步,但也没弄清楚=/
再次感谢!

最佳答案

使用BroadcastReceiver检测下载何时完成:

public class DownloadBroadcastReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();

        if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
            //Show a notification
        }
    }
}

并在您的舱单上登记:
<receiver android:name=".DownloadBroadcastReceiver">
    <intent-filter>
        <action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>
    </intent-filter>
</receiver>

10-08 18:02