对不起,如果这个问题已经问过了,我找了很多这个问题,但没有得到解决办法。
我正在开发一个安卓应用程序,它使用安卓的PDFDocument库生成PDF文件。
有一些奇怪的问题,在生成PDF文件之后,它在电话的文件资源管理器中是可见的,但在计算机文件资源管理器(如Mac的Android文件传输、Windows的我的计算机和Ubuntu的文件资源管理器)中是不可见的,我想我在代码中遗漏了一些东西。请帮帮忙。
这里是我的代码
PdfDocument document = new PdfDocument();
PdfDocument.PageInfo pageinfo = new PdfDocument.PageInfo.Builder(PAGEWIDTH,PAGEHEIGHT,1).create();
PdfDocument.Page page = document.startPage(pageinfo);
Canvas canvas = page.getCanvas();
Paint paint = new Paint();
paint.setTextSize(getResources().getDimension(R.dimen.textsize));
paint.setTextAlign(Paint.Align.CENTER);
paint.setColor(ContextCompat.getColor(getApplicationContext(),R.color.colorName));
canvas.drawText(getResources().getString(R.string.app_name),PAGEWIDTH/2,50,paint);
document.finishPage(page);
String targetPdf = "/sdcard/documents/myfile.pdf";
File filepath = new File(targetPdf);
try {
filepath.createNewFile();
document.writeTo(new FileOutputStream(filepath));
Toast.makeText(getApplicationContext(),
getResources().getString(R.string.success),
Toast.LENGTH_SHORT).show();
}
catch (IOException e){
e.printStackTrace();
Toast.makeText(getApplicationContext(),
getResources().getString(R.string.error) + e.toString(),
Toast.LENGTH_LONG).show();
}
document.close();电话文件资源管理器图像

计算机文件资源管理器图像

https://stackoverflow.com/questions/46843160
复制相似问题