I'm making an app for my clients, and because of that I don't want to upload it to play store. Because of the user experience I want to make the update process automatic, currently I can download the apk correctly in my documents folder. I searched the google 4 days but I cant get my code working. Im on API level 28. I would like to install the updates in the background, but if the user needs to click install that ok too.
 var filePath = android.os.Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_DOCUMENTS).toString();
 filePath = fileSystemModule.path.join(filePath, "update.apk");
 httpModule.getFile('http://192.168.1.11:8000/' + "android/update.apk", filePath).then((resultFile) => {
     Permissions.requestPermissions(android.Manifest.permission.REQUEST_INSTALL_PACKAGES)
     try {
          const context = utils.ad.getApplicationContext();
          var intent = new android.content.Intent(android.content.Intent.ACTION_INSTALL_PACKAGE);
          var data = android.support.v4.content.FileProvider.getUriForFile(application.android.context, "org.nativescipt.ITPalert.provider", new java.io.File(filePath))
          intent.setData(data);
          intent.setType("application/vnd.android.package-archive");
          intent.setFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK); // without this flag android returned a intent error!
          intent.setFlags(android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION)
          context.startActivity(intent)
        }
        catch(e) {
          console.log(e)
        }
    }, (e) => {
        console.log('error' + e)
    })
file_paths.xml
<paths xmlns:android="http://schemas.android.com/apk/res/android">
   <files-path name="just_a_name" path=""/>
   <external-path name="external_files" path="."/>
</paths>
AndroidManifest.xml
 ...
 <application ...>
   <provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="org.nativescipt.ITPalert.provider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_paths"/>
    </provider>
 </application>
Error:
 [Error: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.INSTALL_PACKAGE typ=application/vnd.android.package-archive flg=0x1 }
JS:     android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1968)
JS:     android.app.Instrumentation.execStartActivity(Instrumentation.java:1622)
JS:     android.app.ContextImpl.startActivity(ContextImpl.java:868)
JS:     android.app.ContextImpl.startActivity(ContextImpl.java:845)
Currently Im using android 8.0. However I modify my code I get this error, if I open the file in filebrowser I can install it manually.
 
     
    