Pavan Patil
Pavan Patil

Reputation: 66

Getting Sending Failed Error while sending pdf through my app to whatsapp in android 11

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

Answers (3)

A.M
A.M

Reputation: 1

👍changing uri to file provider works

Upvotes: 0

Pavan Patil
Pavan Patil

Reputation: 66

instead of

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

use

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

Upvotes: 2

blackapps
blackapps

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

Related Questions