title: Error Uploading Video with FileProvider on Android
body: <p>My app has a video in the files directory that I am having trouble sharing with other apps.  I am using a FileProvider to get a Uri to share. However, it does not appear to be working for some apps (works with GMail and Google Drive but not with YouTube or Facebook).  Is there something I am missing?       </p>
  
  <pre><code>mButton.setOnClickListener( new View.OnClickListener()
          {
              @Override
              public void onClick( final View theView ) {
                  File theMovie = new File( getActivity().getFilesDir() + File.separator + "Data/test.mp4" );
                  Uri theMovieUri = FileProvider.getUriForFile( getActivity(), "com.test.provider_demo", theMovie );
                  final Intent theShareIntent = new Intent();
                  theShareIntent.setAction( Intent.ACTION_SEND );
                  theShareIntent.setFlags( Intent.FLAG_GRANT_READ_URI_PERMISSION );
                  theShareIntent.putExtra( Intent.EXTRA_STREAM, theMovieUri );
                  theShareIntent.setDataAndType( theMovieUri, URLConnection.guessContentTypeFromName( theMovieUri.toString() ) );
  
                  List&lt;ResolveInfo &gt; theResolveInfos = getActivity().getPackageManager().queryIntentActivities( theShareIntent, PackageManager.MATCH_DEFAULT_ONLY );
                  for( ResolveInfo theResolveInfo : theResolveInfos ){
                      String thePackageName = theResolveInfo.activityInfo.packageName;
                      getActivity().grantUriPermission( thePackageName, theMovieUri, Intent.FLAG_GRANT_READ_URI_PERMISSION );
                  }
  
                  getActivity().startActivity( Intent.createChooser( theShareIntent, "Share me!" ) );
              }
          } );
  </code></pre>
  
  <p>FileProvider element from manifest</p>
  
  <pre><code>   &lt;provider
          android:authorities="com.test.provider_demo"
          android:name="android.support.v4.content.FileProvider"
          android:exported="false"
          android:grantUriPermissions="true"&gt;
          &lt;meta-data
              android:name="android.support.FILE_PROVIDER_PATHS"
              android:resource="@xml/file_provider_path" /&gt;
      &lt;/provider&gt;
  </code></pre>
  
  <p>YouTube Crashes here's the logcat</p>
  
  <pre><code>01-23 10:34:46.814  12562-13866/? E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #2
  Process: com.google.android.youtube, PID: 12562
  java.lang.RuntimeException: An error occured while executing doInBackground()
          at android.os.AsyncTask$3.done(AsyncTask.java:300)
          at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
          at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
          at java.util.concurrent.FutureTask.run(FutureTask.java:242)
          at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
          at java.lang.Thread.run(Thread.java:841)
   Caused by: java.lang.NullPointerException
          at bif.a(SourceFile:504)
          at bif.a(SourceFile:85)
          at bih.doInBackground(SourceFile:274)
          at android.os.AsyncTask$2.call(AsyncTask.java:288)
          at java.util.concurrent.FutureTask.run(FutureTask.java:237) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) at java.lang.Thread.run(Thread.java:841)
  </code></pre>