Reputation: 1
guys, can you help so that the install dialog doesn't pop up..?
which makes the force install process
Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
intent.setDataAndType(getUriFromFile(location), "application/vnd.android.package-archive");
List<ResolveInfo> resInfoList = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
context.grantUriPermission(packageName, getUriFromFile(location), Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
} else {
intent.setAction(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
intent.setDataAndType(getUriFromFile(location), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
context.startActivity(intent);
Upvotes: 0
Views: 813
Reputation: 723
Unfortunately, you can't update without showing a dialog. But after you show the dialog and get the permission, you can make the application update in the background and you can inform the user with callback. The solution in this issue may be useful to you. link
Upvotes: 0
Reputation: 93559
No. Imagine if malware could force install anything they want without a confirmation. That's why you can't either.
Upvotes: 1