在Android 11中,应用程序需要通过FileProvider来共享文件,以便其他应用程序可以访问并处理文件。以下是示例代码:
File file = new File(filePath);
Uri uri = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
? FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".provider", file)
: Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_SEND)
.setType("application/pdf")
.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent, "Share PDF file"));
这样,就可以在Android 11上分享PDF文件了。