java - 如何将存储在资产文件夹中的 pdf 文件共享到 Whatsapp
问题描述
如何将存储在资产文件夹中的 pdf 文件共享到 Whatsapp。
路径=src/main/assets/alto.pdf
ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.WRITE_EXTERNAL_STORAGE}, PackageManager.PERMISSION_GRANTED);
StrictMode.VmPolicy.Builder bilder=new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(bilder.build());
sharebutton=findViewById(R.id.sharebutton);
sharebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
File file = new File( "alto.pdf");
if (!file.exists()){
Toast.makeText(getApplicationContext(),"no file",Toast.LENGTH_SHORT).show();
return;
}Intent intent=new Intent(Intent.ACTION_SEND);
intent.setType("application/pdf");
intent.putExtra(Intent.EXTRA_STREAM,Uri.parse("file://"+file));
startActivity(Intent.createChooser(intent,"share"));
}
});
解决方案
推荐阅读
- c++ - 使用 STL 的 C++ 库的 Visual Studio 二进制兼容性
- ubuntu - ubuntu中的nvidia,已安装但未考虑
- java - 无法安全重写的“android.support.design.widget”
- javascript - jQuery添加
- java - 在 Kotlin 中返回抛出异常
- google-cloud-datastore - 为什么从 Compute Engine 对 Google API 的调用会间歇性地失败,并出现错误“网络无法访问”和 IPv6 子网?
- angular - 从 edge://policy (chrome://policy) 获取 JSON 数据到 Angular 应用
- sql-server - 根据作业类别授予执行代理作业的权限
- django - Django CKEditor 添加 YouTube 插件
- javascript - 如何使用 Swiper 和 RTK Query 实现无限滚动?