title: Share file across Android Users with FileProvider
body: <p>I am looking to share a file with a service running with the <code>android:singleUser</code> attribute. The file is saved into the local data directory for the Android User. So this could be something like one of the follow:</p>
  
  <ul>
  <li>/data/user/0/com.example.fileshare/files/myfile.txt</li>
  <li>/data/user/10/com.example.fileshare/files/myfile.txt</li>
  <li>/data/user/11/com.example.fileshare/files/myfile.txt</li>
  </ul>
  
  <p>I start the service to share this file like:</p>
  
  <pre><code>Uri fileUri = FileProvider.getUriForFile(getApplicationContext(), "com.example.fileshare.fileprovider", file);
  
  Log.d(TAG, "Share File URI: " + fileUri.toString());
  
  Intent shareFileIntent = new Intent(getApplicationContext(), FileSharingService.class);
  shareFileIntent.setAction(Intent.ACTION_SEND);
  shareFileIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
  String mimeType = getContentResolver().getType(fileUri);
  Log.d(TAG, "Share File MIME Type: " + mimeType);
  shareFileIntent.setDataAndType(
       fileUri,
       mimeType);
  
  startService(shareFileIntent);
  </code></pre>
  
  <p>But when I receive the intent that was sent from any user of than the UserHandle.USER_OWNER in my FileSharingService The ContentResolver cannot find the file because the file does not exists in the same users data directory that the service is running in because of the <code>android:singleUser</code> attribute.</p>
  
  <pre><code>@Override
  protected void onHandleIntent(Intent intent) {
      Log.d(TAG, "onHandleIntent - " + intent.getAction());
  
      if (Intent.ACTION_SEND.equals(intent.getAction())) {
          Uri fileUri = intent.getData();
  
          // When I try and read the file it says that the file does not exist. 
          FileInputStream in = getContentResolver().openInputStream(fileUri);
      }
  }
  </code></pre>
  
  <p>Here are the FileProvider and Service in the AndroidManifest.xml:</p>
  
  <pre><code>&lt;provider
      android:name="android.support.v4.content.FileProvider"
      android:authorities="com.example.fileshare.fileprovider"
      android:grantUriPermissions="true" &gt;
      &lt;meta-data
          android:name="android.support.FILE_PROVIDER_PATHS"
          android:resource="@xml/file_paths" /&gt;
  &lt;/provider&gt;
  
  &lt;service
      android:name="com.example.fileshare.FileSharingService"
      android:exported="true"
      android:singleUser="true" &gt;
      &lt;intent-filter&gt;
          &lt;action android:name="android.intent.action.SEND" /&gt;
  
          &lt;category android:name="android.intent.category.DEFAULT" /&gt;
  
          &lt;data android:mimeType="*/*" /&gt;
      &lt;/intent-filter&gt;
  &lt;/service&gt;
  </code></pre>