title: Programmatically install an apk in Android 7 / api24
body: <p>I am trying to get my app to automatically install an apk.  This works fine for api&lt;24.  But for 24, it is failing.  Android has implemented extra security:</p>
  
  <blockquote>
    <p>For apps targeting Android 7.0, the Android framework enforces the StrictMode API policy that prohibits exposing file:// URIs outside your app. If an intent containing a file URI leaves your app, the app fails with a FileUriExposedException exception.</p>
  </blockquote>
  
  <p>So I tried this:</p>
  
  <pre><code>    Uri myuri;
      if (Build.VERSION.SDK_INT &lt; Build.VERSION_CODES.N){
          myuri = Uri.parse("file://"+outapk);
      } else {
          File o = new File(outapk);
          myuri = FileProvider.getUriForFile(con, con.getApplicationContext().getPackageName() + ".provider", o);
      }
      Intent promptInstall = new Intent(Intent.ACTION_VIEW).setDataAndType(myuri,"application/vnd.android.package-archive");
      con.startActivity(promptInstall);
  </code></pre>
  
  <p>but get a fatal exception:</p>
  
  <pre><code>com.android.packageinstaller "Caused by: java.lang.SecurityException: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord{b42ee8a 6826:com.android.packageinstaller/u0a15} (pid=6826, uid=10015) that is not exported from uid 10066". 
  </code></pre>
  
  <p>I have export=true in my manifest.</p>
  
  <p>The problem seems to be that packageinstaller cannot use a content:// uri.</p>
  
  <p>Are there any ways to allow an app to progammatically install an apk with api24?</p>