title: Sharing a file with Android Intent: File extension is removed
body: <p>I'm using the following code to share an audio file with Android Studio 3.3.2 and Java. The file is extracted from the /raw/ folder. </p>
  
  <pre><code>public void funktionTeilen(String file) {
      Uri uri = Uri.parse("android.resource://" + this.getPackageName() + "/raw/" + file);
      Intent share = new Intent(Intent.ACTION_SEND);
      share.setType("audio/mpeg3");
      share.putExtra(Intent.EXTRA_STREAM, uri);
      startActivity(Intent.createChooser(share, "Audio teilen"));
  }
  </code></pre>
  
  <p>In principle the sharing works fine, but the file is sent without a file extension, which of course makes it unreadable by most apps. If I add the file extension manually (for example after downloading it from the e-mail client), the MP3 works fine.</p>
  
  <p>"file" is fed in by another function and corresponds to the file name from the raw folder. It is also found basically, otherwise the sharing process would not work at all.</p>
  
  <p>So, how can I share a file with retention of the file extension? Thanks for your help!</p>
  
  <p><strong>Update #1</strong></p>
  
  <pre><code>public void funktionTeilen(String Datei) {
  
  
      try {
          File tmpFile = new File(this.getCacheDir() + "/tmpfile.mp3");
          InputStream in = getResources().openRawResource(R.raw.meise1);
          FileOutputStream out = new FileOutputStream(tmpFile, true);
          byte[] buff = new byte[1024];
          int read = 0;
  
          try {
              while ((read = in.read(buff)) &gt; 0) {
                  out.write(buff, 0, read);
              }
          } finally {
              in.close();
              out.close();
          }
  
          // Uri uri = FileProvider.getUriForFile(this, this.getPackageName(), tmpFile);
          Uri uri = Uri.fromFile(tmpFile);
          Intent share = new Intent(Intent.ACTION_SEND);
          share.setType("audio/*");
          share.putExtra(Intent.EXTRA_STREAM, uri);
          startActivity(Intent.createChooser(share, "Audio teilen"));
  
      } catch (Exception e) {
          Toast.makeText(MainActivity.this, e.toString(), Toast.LENGTH_LONG).show();
      }
  
  }
  </code></pre>