Background scanning nativescript-vue



Dear all,

I am using the following plugin to scan for bluetoothdevices:

I am using nativescript-vue and would like to perform scanning on the background. I read this piece on the docs:

But how should i use this within nativescript-vue(npm)?
I read this article: but am afraid this won’t help me with what I’m trying to achieve.

How would you guys go about background scanning within nativescript-vue?

Kindest regards,


This plugin doesn’t involve any UI component, so you have nothing specific to do with Vue. Use it just like any other JavaScript library you would use in Vue.


But how do i do background scanning in nativescript-vue?
The question was not that clear probably


The plugin gives you JS interface for native apis, bluetooth.startScanning(..) gives you everything - you are not directly accessing any native apis here so I don’t really get what exactly is the issue you are facing in calling these methods.


Forget about the plugin, it is non important, I have 0 issues with the plugin.

I want to execute a method in the background from vue; i have this method:


I want to invoke this method every 30 seconds when the app is not opened.
It is not open in recent apps either. Just a backgroundtask.


Do not use a function from Vue’s context, just use a simple JavaScript function.


And how would I do that?

Currently I have an interval set in mounted():

mounted() {
    this.scanInterval = setInterval(function () {
    }.bind(this), 30000); 

This unfortunately only works for approximately 3 minutes after the user closed the application.

I tried workers but they too are killed when the main thread is stopped.

So how do I create a background task in javascript that is running even when the application is closed (not in recent apps anymore) and runs every 30 seconds?


Just refer the demo app, you can use the same code.

Which platform and OS version you are testing it with?


The minimum is 15min.

I want the job to run every 30 seconds, maybe even more.
Whatsapp is instantly receiving messages, how do we do that?

I am debugging on a Samsung Galaxy S7(SM-930F) running Android 8.0.0
As for iOS I don’t know yet, I do not have access to an Apple device at the moment.


Sorry, I’m very much confused now. Is it about working with bluetooth or running a background job?



I want to send the location determined by beacons to the server in the backgroundjob
Every 30 seconds even when the app is in the background or killed.


You have found the perfect example for background services already. You can register a broadcast receiver to get updates immediately, check available options in the official android docs.