Home > Software engineering >  Getting Sending Failed Error while sending pdf through my app to whatsapp in android 11
Getting Sending Failed Error while sending pdf through my app to whatsapp in android 11

Time:10-30

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();
                }
            }

CodePudding user response:

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.

CodePudding user response:

insteed of Uri fileuri = Uri.parse("file://" file);

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

  • Related