I have a bunch of Android devices which are to be flashed with custom ROMs and given out to clients. As part of that ROM will be a 'support' app, which is tied to the device. It can't be published to Google Play. I need to be able to offer users the opportunity to download and install updated versions of the software. I have checking, download and install code already implemented however it relies on the devices being configured to enable installation of apps from unknown sources. I need the device to be able to download and install this particular apk, whilst still not allowing any other apps from unknown sources to be installed.
Is this possible?
(edit: to clarify how the chosen answer finally worked)
The code added to the activity was this:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() +"/update.apk")), "application/vnd.android.package-archive");
intent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
intent.putExtra(Intent.EXTRA_ALLOW_REPLACE, true);
startActivityForResult(intent, 0);
To the android manifest, the following code was added:
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
After installing the app, I used a root file explorer to move the apk from /user/apps
to /system/apps
then after resetting the phone the app was able to install itself, over the top of itself, without being prompted for the user to enable untrusted sources. The install prompt, listing the permissions the app requires and giving the user the choice to install or not still appears, but that is fine.