'intent.extra.NOT_UNKNOWN_SOURCE not working in Android-11

I have an installer app which installs/replaces an existing app using the below code. Up till Android-10 it works. But not in Android-11. So far my searches did not say any deprecation of android.intent.extra.NOT_UNKNOWN_SOURCE. So it should have worked.

Any idea?

Code snippet installing the app.

Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
intent.setDataAndType(Uri.fromFile(apk), "application/vnd.android.package-archive");
intent.putExtra("android.intent.extra.RETURN_RESULT", true);
intent.putExtra("android.intent.extra.NOT_UNKNOWN_SOURCE", true);
intent.putExtra("android.intent.extra.ALLOW_REPLACE", true);
startActivityForResult(intent, REQ_INSTALL_APK);


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source