直到Android派,我的代码才能正常工作。但是当我更新到Android 10时,它会显示以下错误。怎么解决呢?
E/SubsamplingScaleImageView:未能初始化位图解码器java.io.FileNotFoundException:打开失败: ENOENT (没有此类文件或目录)在android.os.ParcelFileDescriptor.openInternal(ParcelFileDescriptor.java:315) at android.os.ParcelFileDescriptor.open(ParcelFileDescriptor.java:220) at com.pdfview.PDFRegionDecoder.init(PDFRegionDecoder.kt:25) at com.pdfview.subsamplincscaleimageview.SubsamplingScaleImageView$TilesInitTask.doInBackground(SubsamplingScaleImageView.java:1564) at com.pdfview.subsamplincscaleimageview.SubsamplingScaleImageView$TilesInitTask.doInBackground( android.os.AsyncTask$3.call(AsyncTask.java:378) ) java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:919)
我正在使用以下代码。
URL url = new URL(aurl[0]);
URLConnection conexion = url.openConnection();
conexion.connect();
int lenghtOfFile = conexion.getContentLength();
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
File folder = new File(extStorageDirectory, "tmf");
folder.mkdir();
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream(folder + "/contract.pdf");
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
total += count;
publishProgress(""+(int)((total*100)/lenghtOfFile));
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();`发布于 2019-12-24 06:15:18
试试下面的代码。
String destination = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/";
String fileName = "filename.pdf";
destination += fileName;
final Uri uri = Uri.parse("file://" + destination);
String url = downloadurl; //paste url here
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setDescription("Downloading....");
request.setTitle(" TITLE ");
request.setDestinationUri(uri);
final DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
final long downloadId = manager.enqueue(request);
final String finalDestination = destination;
BroadcastReceiver onComplete = new BroadcastReceiver() {
public void onReceive(Context ctxt, Intent intent) {
Log.d("Update status", "Download completed");
unregisterReceiver(this);
}
};
registerReceiver(onComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));发布于 2019-12-24 06:49:11
如果您的应用程序正在访问Q,则不能直接向外部公共存储写入。您必须使用MediaStore将文件保存到一个可公开访问的位置。
您可以使用以下引用代码来使用MediaStore存储文件。请注意,您需要android.permission.WRITE_EXTERNAL_STORAGE来使用MediaStore存储文件。
val cv = ContentValues().apply {
put(MediaStore.Files.FileColumns.DISPLAY_NAME, "mypdf.pdf")
}
val uri = contentResolver.insert(MediaStore.Files.getContentUri("pdfs"), cv)
uri?.let {
val out = contentResolver.openOutputStream(it)
}发布于 2019-12-24 06:16:55
您是否获得了读取外部存储的权限,也没有找到错误状态文件,请确保正在创建该文件。
https://stackoverflow.com/questions/59464452
复制相似问题