Reputation: 66
Sending pdf files from my app to whatsapp was working until it was used on android 11 device I have added this permission also and have asked for runtime permission
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();
}
}
Upvotes: 3
Views: 1044
Reputation: 66
instead of
Uri fileUri = Uri.parse("file://" + file);
use
Uri fileUri = FileProvider.getUriForFile(getApplicationContext(), "com.example.packagename.fileprovider", file);
Upvotes: 2
Reputation: 9282
Uri fileuri = Uri.parse("file://" + file);
Dont use a file uri but use a FileProvider to serve your file and can use a content scheme uri.
Upvotes: 1