Android 2.3 上的后台 HTML5 WebApps

发布于 2024-10-22 20:06:12 字数 333 浏览 5 评论 0原文

iOS 4.2+ 允许某些 Web 应用程序在后台运行,没有任何特殊要求。

如何在 Android 上在后台运行 Web 应用程序(例如继续播放音乐)?

有关示例,请参阅 https://coolaj86.com/demos/sandbox/html5 -audio-tag.html

开始在 iPod/iPad/iPhone 上播放音乐样本,然后单击“后台”应用程序。 双击下方菜单并从左向右滑动即可访问播放器控件。

iOS 4.2+ allows certain webapps to run in the background, without any special requirements.

How is it possible to run a webapp in the background on Android (to continue playing music, for example)?

For an example, see https://coolaj86.com/demos/sandbox/html5-audio-tag.html

Begin playing the music sample on your iPod/iPad/iPhone, then click to "background" the app.
Double click and swipe from left to right in the lower menu to access the player controls.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无所的.畏惧 2024-10-29 20:06:12

这是通过使用后台服务来完成的。

That is done by using background Services.

玉环 2024-10-29 20:06:12

正如 Robby 所说,要做到这一点,您需要使用服务。

显然,您不能拥有“后台网页”,就像任何浏览器都不能拥有其中之一一样。解决方案是使用WebView的setJavascriptInterface()在WebView中创建后台服务和HTML5/JS前端之间的接口。使用 javascript 接口,您可以创建自己的绑定以从 javascript 内部调用 Java 代码。

该服务可用于保留后台功能,但当应用程序返回前台时,WebView 需要再次通过 javascript 接口绑定到它,获取所需的数据,并填充其 UI。

As Robby said, to do this you need to use a Service.

Obviously you can't have a "background web page" just like you can't have one of those with any browser. The solution is to use WebView's setJavascriptInterface() to create an interface between your background service and HTML5/JS front-end in the WebView. With a javascript interface, you can create your own bindings to call into Java code from inside of your javascript.

The service can be used to preserve the background functionality, but when the app comes back into the foreground the WebView needs to bind to it via javascript interface again, get the data it needs, and populate its UI.

野却迷人 2024-10-29 20:06:12

这并不是一个真正的答案,但如果我们可以请求网页继续在后台运行,那不是很好吗?当然,页面应该需要用户的明确(并且始终可撤销)同意,但这对于(本机)浏览器来说似乎并不是完全不可能处理的事情? :( 我们已经提示用户允许使用其他 API,例如位置 API - 为什么不也使用运行即服务 API?

对于所有 Web 应用程序来说,这将是一个巨大的进步,与我的本机应用程序相同意见!<3

This is not really an answer, but wouldn't it be great though, if we could request a webpage to continue running in the background. Of course the page should need an explicit (and at all time revokable) consent from the user, but that doesn't seem like a completely impossible thing to handle for the (native) browsers? :( We already prompts the users for permission to use other APIs like the location API - why not also a run-as-a-service API?

It would be such a huge step forward for all webapps to be equal to native apps in my opinion! <3

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文