android - 通过我的应用程序将 pdf 发送到 android 11 中的 whatsapp 时出现发送失败错误

标签 android android-permissions android-11 file-sharing

将 pdf 文件从我的应用程序发送到 whatsapp 一直有效,直到它被用于 android 11 设备 我也添加了此权限并请求运行时权限

if (Build.VERSION.SDK_INT == Build.VERSION_CODES.R){
                if (isPermissonGranted()){
                    Log.i("storageproblem","app runtime permission granted");
                    Uri fileuri = Uri.parse("file://" + file);
                    Intent share = new Intent(Intent.ACTION_SEND);
                    share.putExtra(Intent.EXTRA_STREAM, fileuri);
                    share.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                    share.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                    share.setPackage("com.whatsapp");
                    share.setType("*/*");
                    startActivity(share);
                }else{
                    Log.i("storageproblem","app runtime permission not granted");
                    takePermisson();
                }
            }

最佳答案

代替

Uri fileUri = Uri.parse("file://" + file);

使用

Uri fileUri = FileProvider.getUriForFile(getApplicationContext(), "com.example.packagename.fileprovider", file);

关于android - 通过我的应用程序将 pdf 发送到 android 11 中的 whatsapp 时出现发送失败错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69776957/

相关文章:

android - Xamarin.Android、AndroidManifest.xml、AndroidManifestMerger、xmlns :tools schema, 始终手动替换

android - 从不同的线程修改 View

android - 我的手电筒应用程序代码无法正常工作

Cordova Android WebRTC 无法捕获视频 - 仅限 AUDO。权限问题?

android - 在 Android 11 中从最近的文件夹中选择 PDF 文件时出现 NullPointException :Uri

android - 如何使用 Android NDK 以正确的依赖顺序构建多个项目?

android - 如何在 Lollipop 前手机上的点击事件中更改 CardView 的蓝色

android-11 - Android 11 - 在存储根目录下创建应用程序目录作为共享文件夹

Android NotificationChannel 在运行时请求多个 channel 的权限?

android - 在 Android R 上创建目录