1

I have developed application same like playstore and written below code for apk installation, which is not working in Android 10 (Android Q) device users.

File downloadedFile = new File(download.getFile());if (downloadedFile.exists()) {
downloadedFile.setExecutable(false);
downloadedFile.setWritable(false);
downloadedFile.setReadable(true);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(downloadedFile), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);}

Its already published and user unable to install the new version. Kindly suggest the solution for app update in users device without front end code change.

  • Please see the link https://stackoverflow.com/questions/4967669/android-install-apk-programmatically – Muhammad Yaseen Mar 05 '20 at 11:11
  • Please try this code: https://stackoverflow.com/a/60523219/4030207 I wish work for you. – Praful Patel Mar 05 '20 at 11:15
  • This code will not work on Android 7.0+ and higher, as you will crash with a `FileUriExposedException`. Use `FileProvider`, not `Uri.fromFile()`. On Android 10+, `ACTION_INSTALL_PACKAGE` was deprecated as an action, with Google steering developers to use `PackageInstaller` instead. While they did not mention `ACTION_VIEW`, one imagines that it too is no longer appropriate for installing apps. – CommonsWare Mar 05 '20 at 12:07

0 Answers0