I wrote a method to install apk in all version of android and it works until android 8 . but it seems android 8 do not response to this method
install_apk(File file) { try { if (file.exists()) { String[] fileNameArray = file.getName().split(Pattern.quote(".")); if (fileNameArray[fileNameArray.length - 1].equals("apk")) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { Uri downloaded_apk = getFileUri(context, file); Intent intent = new Intent(Intent.ACTION_VIEW).setDataAndType(downloaded_apk, "application/vnd.android.package-archive"); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); context.startActivity(intent); } else { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } } } } catch (Exception e) { e.printStackTrace(); } }
and this method for get uri on api >= 23
Uri getFileUri(Context context, File file) { return FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".HelperClasses.GenericFileProvider" , file); }
Just open your browser, find the APK file you want to download, and tap it – you should then be able to see it downloading on the top bar of your device. Once it's downloaded, open Downloads, tap on the APK file and tap Yes when prompted. The app will begin installing on your device.
If you run an APK in Ubuntu with Anbox, it will install like any other Android app. You have two options for installing apps on Anbox: Sideload. Install Google Play.
You should be add a new permission.
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With