我正在做Android的任务。
我从 URL 下载文件并保存在 Android 手机的内部存储/目录中?我的代码写在下面,但这是外部存储代码,我想要内部存储代码。
public void onClick(View v) {
Toast.makeText(Computer.this,"Please Wait until the file is download",Toast.LENGTH_LONG).show();
downloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
Uri uri = Uri.parse("url");
DownloadManager.Request request = new DownloadManager.Request(uri);
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI | DownloadManager.Request.NETWORK_MOBILE);
request.setAllowedOverRoaming(false);
request.setTitle("" + "filename" + ".pdf");
request.setVisibleInDownloadsUi(true);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
Long reference = downloadManager.enqueue(request);
request.setDestinationInExternalFilesDir(Environment.DIRECTORY_DOWNLOADS, "/"+ "filename");
refid = downloadManager.enqueue(request);
Log.e("OUT", "" + refid);
这是外部存储代码,但我想保存在Android手机的内部存储中。
最佳答案
您不能使用DownloadManager
直接下载到your app's portion of internal storage 。您需要use OkHttp或其他一些进程内 HTTP 客户端 API。
关于java - 下载内部存储器中的 PDF 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56834205/