i am unable to pass the image using share intent.The app runs but when i try to send image to a friend in whatsApp it says "Sharing failed, please try again" and on sharing with gmail it says "Cannot attach empty file" .I have also set permission in Manifests. I guess there is some issue in creating file or maybe the path.
please Check the below code:
share.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Bitmap icon = BitmapFactory.decodeResource(getResources(), img);
            Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
            sharingIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            sharingIntent.setType("image/*");
            ByteArrayOutputStream bytes = new ByteArrayOutputStream();
            icon.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
             File f = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)+ File.separator + "temporary_file.jpg");
           // File f1=Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
            //File f = new File(Environment.getExternalStorageDirectory() + "/save_picture", "temporary_file.jpg");
            try {
              f.createNewFile();
               // f.mkdir();
                f.createNewFile();
                FileOutputStream fo = new FileOutputStream(f);
                fo.write(bytes.toByteArray());
            } catch (IOException e) {
                e.printStackTrace();
            }
           // sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("content://" + Environment.getExternalStorageDirectory()));
             sharingIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse("content:///sdcard/temporary_file.jpg"));
            startActivity(Intent.createChooser(sharingIntent, "Share via: "));
        }
    });
 
     
     
    