2

I've successfully downloaded my apk file to internal storage.

However when running it I get an "No activity found to handle intent" error.

Here is my code to run the apk file.

// Old version
if(Build.VERSION.SDK_INT <= Build.VERSION_CODES.N)
{
File apkFile = new File(this.pathToFile);
     if(apkFile.exists())
     {
          Uri apkURI = Uri.fromFile(apkFile);
          Intent intent = new Intent(Intent.ACTION_VIEW);
          intent.setData(apkURI);
          intent.setType("application/vnd.android.package-archive");
          intent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, false);
          intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          context.startActivity(intent);
    }
}
14
  • my file path is actually /data/com.me.appName/files/update.apk. That is an impossible path. Only on a rooted device it could have been created.
    – greenapps
    Nov 17, 2017 at 9:24
  • successfully downloaded my apk file to internal storage.. Well how did you manage to do that? Considering that impossible path.
    – greenapps
    Nov 17, 2017 at 9:25
  • You were talking about this.pathToFile?
    – greenapps
    Nov 17, 2017 at 9:27
  • Android how to install apk stored in internal storage. Wrong subject.
    – greenapps
    Nov 17, 2017 at 9:29
  • context.openFileOutput("app.apk", Context.MODE_PRIVATE); Is where it was saved. Then I stored pathToFile = context.getFilesDir().toString() + "/app.apk";
    – mocode10
    Nov 17, 2017 at 17:53

1 Answer 1

0

The apk cannot be installed using a content scheme.

You have to offer Android a file path to the apk file.

So do away with the FileProvider.

Further you should download to getExternalStorageDirectory() or getFilesDir() instead.

10
  • I do download to getFilesDir(). File apkFile = new File(context.getFilesDir().getAbsolutePath() + "/app.apk");
    – mocode10
    Nov 17, 2017 at 19:48
  • Yes i know. So dont do that was what i said.
    – greenapps
    Nov 17, 2017 at 19:48
  • Is there any reason to choose ExternalStorage over getFilesDir()? My reason for choosing getFilesDir is because every device has it where not every device has external storage media.
    – mocode10
    Nov 17, 2017 at 19:50
  • Every device has external storage. And a lot of devices have also removeble storage if a micro SD card can be inserted. Do not use getFilesDir() as it s private internal storage for your app only. So other apps have no acces. Im afraid that your apk cannot be installed from internal storage. Well if Android installs the apk then it should have acces. But please try both. Why not?
    – greenapps
    Nov 17, 2017 at 19:56
  • The apk is not the app that tries to instal it? Or is it?
    – greenapps
    Nov 17, 2017 at 19:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.