将 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/