简体   繁体   中英

Android how to install apk stored in internal storage

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);
    }
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM