网站(HTML5、JavaScript)能否访问移动设备(Android/iPhone)的联系人列表、SDCard 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24076800/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can a website (HTML5,JavaScript) access a mobile device's (android/iPhone) contact list, SDCard files
提问by chaitanyad
Can a website (HTML5,JavaScript) access a mobile device's (android/iPhone)
contact list, SDCard files?
A website as in one opened in a browser not a phonegap application/webapp.
网站(HTML5、JavaScript)可以访问移动设备(Android/iPhone)的
联系人列表、SDCard 文件吗?一个在浏览器中打开的网站,而不是 phonegap 应用程序/webapp。
采纳答案by Imnl
You can't access the mobile device file system through a website, it would be a major security problem. You might be able to steal all user files if you can access them through the browser.hope this helps.
您无法通过网站访问移动设备文件系统,这将是一个重大的安全问题。如果您可以通过浏览器访问它们,您可能能够窃取所有用户文件。希望这会有所帮助。
回答by jbandi
There was an attempt at the W3C to create a browser API to access contacts from the browser. This is often mentioned as one of the new HTML5 APIs.
W3C 曾尝试创建浏览器 API 以从浏览器访问联系人。这经常被提及为新的 HTML5 API 之一。
However the attempt never became a real specification and never got implemented by any browser vendors. Now it is officially discontinued:
然而,这种尝试从未成为真正的规范,也从未被任何浏览器供应商实施。现在正式停产了:
回答by Haris
At this point in time there is no way to access the internal APIs from Android, iOS and Windows Phone via a simple website. This also precludes you from accessing aspects such as the contact list because these are all only accessible via API calls.
目前还没有办法通过简单的网站从 Android、iOS 和 Windows Phone 访问内部 API。这也使您无法访问联系人列表等方面,因为这些都只能通过 API 调用访问。
Solutions that allow you to code phone apps or web apps in JavaScript or HTML5 and still grant access to APIs do so by utilizing a wrapper with calls back to the native code. But you can't call native code from an external source such as a website.
允许您使用 JavaScript 或 HTML5 编写电话应用程序或 Web 应用程序并仍授予对 API 访问权限的解决方案,通过使用带有回调本地代码的包装器来实现。但是您不能从外部源(例如网站)调用本机代码。
回答by Chuka Charles Okoye
Am not so sure if the author of this question will still be interested in a solution but I use this on my apps, its really a handy way of access native api from html5 apps. http://bridgeit.mobi/bridgeit.html#features
我不太确定这个问题的作者是否仍然对解决方案感兴趣,但我在我的应用程序中使用它,它确实是一种从 html5 应用程序访问本机 api 的便捷方式。http://bridgeit.mobi/bridgeit.html#features
BridgeIt enables any web application to access a wide range of mobile device capabilities using a simple JavaScript API.
BridgeIt 使任何 Web 应用程序都可以使用简单的 JavaScript API 访问广泛的移动设备功能。
Using this tool is as easy as 1, 2, 3…
使用这个工具就像 1、2、3 一样简单……
Include the BridgeIt JavaScript in your page
<script type="text/javascript" src="http://api.bridgeit.mobi/bridgeit/bridgeit.js"></script>
Attach a BridgeIt call to some action element on your page, and provide a callback to handle returned values from BridgeIt. For instance, a button to retrieve a contact from the address book...
bridgeit.fetchContact('element_ID', callback_Function);
Access the page from your mobile browser. If the BridgeIt utility app is not already installed, you will be prompted to do so. Once the BridgeIt utility app is installed, your application can access all of BridgeIt's native features.
在您的页面中包含 BridgeIt JavaScript
<script type="text/javascript" src="http://api.bridgeit.mobi/bridgeit/bridgeit.js"></script>
将 BridgeIt 调用附加到页面上的某个操作元素,并提供回调以处理来自 BridgeIt 的返回值。例如,一个从地址簿中检索联系人的按钮......
bridgeit.fetchContact('element_ID', callback_Function);
从您的移动浏览器访问该页面。如果尚未安装 BridgeIt 实用程序应用程序,系统将提示您安装。一旦安装了 BridgeIt 实用程序应用程序,您的应用程序就可以访问 BridgeIt 的所有本机功能。
Example code can be found here https://github.com/bridgeit/bridgeit.js/wiki/Contact-List-Tutorial
示例代码可以在这里找到https://github.com/bridgeit/bridgeit.js/wiki/Contact-List-Tutorial
回答by TCD
https://developers.google.com/people/
https://developers.google.com/people/
You can't access Contacts by website stored on phone, but you can do it server side using People API. If user stored everything on the cloud - you win. Perhaps this is only way to provide native-like experience on your website
您无法通过存储在手机上的网站访问联系人,但您可以使用 People API 在服务器端进行访问。如果用户将所有内容都存储在云端 - 您就赢了。也许这是在您的网站上提供类似原生体验的唯一方法
回答by Meekohi
Chrome has since shipped their own version of a "Contact Picker" HTML5 API in Chrome 80: https://web.dev/contact-picker.
Chrome 已经在 Chrome 80 中发布了自己的“联系人选择器”HTML5 API 版本:https: //web.dev/contact-picker。
Chrome only: it is not a W3C Standard nor is it on the W3C Standards Track.
仅 Chrome:它不是 W3C 标准,也不在 W3C 标准轨道上。
selectRecipientsButton.addEventListener('click', async () => {
const contacts = await navigator.contacts.select(['name', 'email'], {multiple: true});
if (!contacts.length) {
// No contacts were selected in the picker.
return;
}
// Use the names and e-mail addresses in |contacts| to populate the
// recipients field in the website's UI.
populateRecipients(contacts);
});
回答by Nay
You can access address book using Autofill feature of safari browser in iOS devices (but settings > safari > autofill > contact info must be turn on). And the name field in must be "name, email, phone, tel, etc" to get autofill works properly. It works only in Safari but not in other browsers.
您可以在 iOS 设备中使用 safari 浏览器的自动填充功能访问地址簿(但必须打开设置 > safari > 自动填充 > 联系信息)。并且名称字段必须是“姓名、电子邮件、电话、电话等”才能使自动填充正常工作。它仅适用于 Safari 而不适用于其他浏览器。
回答by Dinesh Shah
Using pure HTML
使用纯 HTML
<input type="file">
you can access files from mobile device,but you cant access contact.
您可以从移动设备访问文件,但无法访问联系人。