title: Intent to install APK file - Android Nougat
body: <p>I searched extensively and did not find the problem. When you try to install an <code>APK file</code> using an <code>Intent</code> in <code>Android Nougat</code>, it simply does not install and displays the following warning: "There was a problem parsing the package".</p>
  
  <p>It works perfectly to open <code>PDF</code> files, for example, with settings to open this type of file (.<code>PDF</code>). However to install .<code>apk</code> files does not work.</p>
  
  <p><code>LogCat</code> does not show any errors and I can not reach any solution.</p>
  
  <p>What could be wrong?</p>
  
  <p>The following code:</p>
  
  <p><em>Manifest</em>:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
  &lt;uses-permission android:name="android.permission.INSTALL_PACKAGES" /&gt;
  
  &lt;provider
          android:name="android.support.v4.content.FileProvider"
          android:authorities="br.com.xxxxxx.xxxxxx.fileprovider"
          android:exported="false"
          android:grantUriPermissions="true"&gt;
          &lt;meta-data
              android:name="android.support.FILE_PROVIDER_PATHS"
              android:resource="@xml/filepaths"/&gt;
      &lt;/provider&gt;
  </code></pre>
  
  <p>xml/filepaths:</p>
  
  <pre><code>&lt;paths xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  &lt;files-path name="storage/emulated/0" path="."/&gt;
  </code></pre>
  
  <p></p>
  
  <p>Activity:</p>
  
  <pre><code>if(Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.N) {
          try {
              Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
              File file = new File(getContext().getFilesDir(), "app-debug.apk");
              Uri uri = FileProvider.getUriForFile(getContext(), BuildConfig.APPLICATION_ID + ".fileprovider", file);
  
              intent.setDataAndType(uri, "application/vnd.android.package-archive");
              intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
              startActivity(intent);
              finish();
          } catch (Exception e) {
              e.printStackTrace();
          }
      }else{
          try {
              Intent intent = new Intent(Intent.ACTION_VIEW);
              File file = new File(Environment.getExternalStorageDirectory() + "/app-debug.apk");
  
              intent.setAction(android.content.Intent.ACTION_VIEW);
              intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
              intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
              startActivity(intent);
              finish();
          } catch (Exception e) {
              e.getMessage();
          }
      }
  </code></pre>
  
  <p>Please, what could be wrong with this code? Can someone help me?</p>