APK is updating well till targetSdkVersion 24, But it is having an issue in 28(latest). My app is not on PlayStore.if Version Number changes it needs to update. The issue is App is not updated when the version number is incremented in 28 targetSdkVersion Here is my code:
try {
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath() + "/Download/"+appName);
file.setReadable(true, false);
Uri fileUri = Uri.fromFile(file);
if (Build.VERSION.SDK_INT >= 24) {
fileUri = FileProvider.getUriForFile(UpdateActivity.this, getPackageName()+ ".provider",
file);
}
Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE, fileUri);
intent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
intent.setDataAndType(fileUri, "application/vnd.android" + ".package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);
finish();
} catch (Exception e) {
Toast.makeText(this, "Something went Wrong.Remove old XYZ app & install it from Download folder", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
in Manifest:
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.updateapp.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
Provider Path:
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
</paths>
I need it to update APK in targetSdkVersion 28.Appreciate for help thank you