【发布时间】:2022-01-16 08:54:14
【问题描述】:
我在做什么
我正在创建一个 Web 表单,用作 QR 码来打开安装在 android / IOS 手机中的应用程序。当用户扫描二维码时,手机会运行网页表单,网页表单会检查手机内部是否安装了应用程序,如果安装了应用程序,网页表单将打开应用程序,如果没有则打开google播放商店/应用商店网页取决于正在使用的操作系统。
我的问题
现在我的问题是我不知道触发/打开它的应用程序的名称/ID是什么,我唯一知道的是它在设置和主屏幕中被称为 Rymtime .该应用程序的 Google Play 商店链接位于应用商店的here 和here。
PS。我不拥有/创建应用程序,也无权修改其代码。
我的尝试
我曾尝试将其名称直接放入代码中:
window.location = "Rymtime://";
我还尝试将在其 google play 商店网站“www...id=com.time2clock.wai.timeemployee”中找到的“id”东西放入
window.location = "com.time2clock.wai.timeemployee://";
我的代码
我根据this 堆栈溢出问题创建了我的代码。
下面是我的代码:
<body>
...
<button name="data1" type="button" onclick="getOS()">Click</button> //I use button to test out the function
...
</body>
<script type="text/javascript">
function getOS() {
var userAgent = window.navigator.userAgent,
platform = window.navigator.platform,
windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE'], //as I do not own an Iphone I use this to test out the IOS part
iosPlatforms = ['iPhone', 'iPad', 'iPod'],
os = null;
if (iosPlatforms.indexOf(platform) !== -1) {
ios();
} else if (windowsPlatforms.indexOf(platform) !== -1) {
ios(); //as I do not own an Iphone I use this to test out the IOS part
} else if (/Android/.test(userAgent)) {
android();
}
}
function ios() {
setTimeout(function () { window.location = "https://apps.apple.com/my/app/rymtime/id1447217174"; }, 25);
window.location = "Rymtime://"; //I do not test this part because I do not own an Iphone an I am using window to see if the code is being executed, I only check if the website above is runned
}
function android() {
setTimeout(function () { window.location = "https://play.google.com/store/apps/details?id=com.time2clock.wai.timeemployee"; }, 25);
window.location = "Rymtime://"; //The application is not executed thus it redirect to the play store page.
}
</script>
顺便说一句,安装在手机中的应用程序的位置是否与其他应用程序相同?像这样:
somefile\somefile\packageName
或者是这样的:
Username(differ)\somefile\somefile\packageName
谢谢。
【问题讨论】:
-
为了通过URI打开应用,应用需要明确支持。
-
我如何知道应用是否支持它?我只是想让手机安装后自动打开应用。
-
打开应用的应用信息可以在安卓设置中看到。在那里,转到
Open by default并查看Links to open in this app部分。该选项在不同的 android 版本上可能有不同的名称。 -
open by default部分显示No defaults set和所有其他选项,如open supported links和supported web addresses(None)都被禁用。我猜这个应用没有深层链接? -
这也是我的假设。您可以查看此信息如何查找其他应用程序(例如 WhatsApp 为我显示 4 个受支持的链接)。
标签: javascript android iphone webforms