One problem is that Amazon changes the strings for every new model. You could check only for Kindle, Silk and KF* but that could potentially lead to false positives. I have altered the code a bit from one of the examples above to make a bit more readable and easy to maintain.
As of November 18, 2015, the below code should work.
Check https://developer.amazon.com/sdk/fire/specifications.html for new models.
This is the code I wrote to redirect people to my game Luna Puma from my website for both Kindle Fire and Android phones:
<script type="text/javascript"> // <![CDATA[
var ua = navigator.userAgent;
var kindleStrings = [
"Kindle",
"Silk",
"KFTT",
"KFOT",
"KFJWA",
"KFJWI",
"KFSOWI",
"KFTHWA",
"KFTHWI",
"KFAPWA",
"KFAPWI",
"KFASWI",
"KFTBWI",
"KFMEWI",
"KFFOWI",
"KFSAWA",
"KFSAWI",
"KFARWI" ];
var isKindle = false;
for (index = 0; index < kindleStrings.length; index++) {
var matchRegExp = new RegExp (kindleStrings[index]);
if (matchRegExp.test (ua)) {
isKindle = true;
break;
}
}
if (isKindle) {
document.location = "amzn://apps/android?asin=B01859LRE0";
}
var isAndroid = /Android/i.test (ua);
if (isAndroid && !isKindle) {
document.location = "https://play.google.com/store/apps/details?id=com.xanamania.lunapuma";
} // ]]>
</script>