0

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.

  • If the application crashes you did not catch some exception. Look in the Logcat which one. For which sdk int? – blackapps Aug 30 '20 at 18:55
  • Anyhow: You probably have a FileUriExposedException. Your uri from file is not usable now adays. Use a FileProvider to serve your file. – blackapps Aug 30 '20 at 18:57
  • @blackapps the app is not crashing. It is closing the application. And thanks for suggesting FileProvider, I will add implement that. But still, I don't feel that will solve the issue. – JYOTIRMAY GHOSH Aug 30 '20 at 19:25
  • I would call it a crash when i did not close it and it got closed. So what is happening? – blackapps Aug 30 '20 at 19:28

0 Answers0