Let's make it into a more real example, let's say App B reads from twitter and App A shows facebook posts, so you want facebook post URLs to open on App A.
From App B, before the user clicks on a facebook post URL, you can use the PackageManager to check if App A is installed or not, and in case it's not installed you pass app A Google Play url, else you just pass the facebook URL. Note that this will only work if the user is inside App B. It won't work if the user is on chrome for example.
But if the user don't have neither installed, there's nothing you can do.