I’m trying to install an apk via kotlin. My app downloads the apk from github however when trying to install the apk, it says “failed to parse package”
In my androidmanifest.xml I have
<uses-permission android:name="android.permission.INTERNET"
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
and my provider paths xml is
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path
name="files"
path="." />
<cache-path
name="cache"
path="." />
<external-path
name="external"
path="." />
<external-files-path
name="external_files"
path="." />
</paths>
and my kotlin function is
val apkFileUri = FileProvider.getUriForFile(
context,
context.applicationContext.packageName + ".provider",
File(apkFilePath)
)
val install = Intent(Intent.ACTION_VIEW)
install.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
install.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true)
install.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
install.setDataAndType(apkFileUri, "application/vnd.android.package-archive")
context.startActivity(install)
I have checked the md5sum of both the file hosted on GitHub, and the file downloaded by my app, and they both match, and the file downloaded by GitHub is installable by Chrom and the default file manager. I assume then, it’s a permissions issue, but I don’t know what permissions I am missing.
Thanks in advance!