Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a progressive web app (PWA) run a background service on a mobile device to get data from hardware (accelerometer, gps...)?

I see we can check the capabilities of a mobile browser using https://whatwebcando.today/, but can the hardware APIs be queried when not running on foreground?

I mean... With PWA am I able to build an app that gets hardware info while running in background, just like Octo U, for Android, and posts that info to a web server?

like image 685
Rafael Oliveira Avatar asked Jun 13 '17 20:06

Rafael Oliveira


People also ask

Can PWA app run in background?

Using a service worker, a Progressive Web App (PWA) can do work in the background, even when the user isn't using the app. Service workers used to be reserved for native apps, but they are now also available to PWAs, providing a better offline experience.

Does PWA work on mobile?

In addition to PWAs being able to work on all devices, it also doesn't matter which operating system the user has. They work on both Apple and Android devices.

Can Progressive Web Apps access the device hardware features?

A PWA can still work when the device is offline. PWAs can be installed on the operating system. PWAs support push notifications and periodic updates. PWAs can access hardware features.


1 Answers

The modern method of running code "in the background" is by using a service worker, either via its push event handler (triggered via an incoming push message), or via its sync event handler (triggered by an automatic replay of a task that previously failed).

It's not currently possible to access the type of hardware sensors that you're asking about from inside a service worker.

like image 68
Jeff Posnick Avatar answered Sep 20 '22 16:09

Jeff Posnick