I want to implement the OTA feature in android. My app will not be available in the google app store for auto-update. I added a timer that will periodically check for app updates with the server. If the device version miss-match with the server version, the app will get download using Download Manager.
Once the download finish, I am trying to install the updated application.
Uri uri = Uri.fromFile( new File(filePath));
Print.d("Downloaded app file path :: " + uri.toString());
Intent install = new Intent(Intent.ACTION_VIEW);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
install.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
install.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
install.setData(uri);
context.startActivity(install);
} else {
install.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
install.setDataAndType(uri, "application/vnd.android.package-archive");
context.startActivity(install);
// finish()
}
I tried the above code. But the application is getting closed. Although the app is downloaded successfully.