You also can create Firbase Dynamic links which will work as per your requirement. It supports multiple platforms. This link can be created, manually as well as via programming. You can then embed this link in QR code.
If the target app is installed, the link will redirect user to app. If its not installed it will redirect to Play Store/App store/Any other configured website.