capacitor-plugin-backgroundservice
v0.5.2
Published
Plugin to start application as foreground service to run in background continously even if the app is killed or device is rebooted
Downloads
112
Maintainers
Readme
capacitor-plugin-backgroundservice
This plugin is designed to start the application as a foreground service, allowing it to run continuously in the background even if the app is killed. It also ensures the service restarts automatically when the Android device is booted or restarted.
Important Note
This plugin does not expose any explicit methods for use in JavaScript. All functionality is handled natively through Java code and configurations in the Android manifest file. You will need to set up the required native components to enable and customize the background service behavior.
Install
npm install capacitor-plugin-backgroundservice
npx cap syncAPI
StartBackgroundService(...)requestNotificationPermission()connectBleDevice(...)isMqttClientConnected()connectMqtt(...)publishMessage(...)subscribeToNormalDLTopic(...)subscribeToOtherDLTopic(...)subscribeToAuthTopic(...)disconnectMqttBroker()addListener(string, ...)- Interfaces
StartBackgroundService(...)
StartBackgroundService(options: { baseURL: string; basicAUTH: string; apiSuffix: string; deviceUUID: string; deviceType: string | null; macAddress: string | null; authPayload: { parameters: { header: string; }; }; }) => Promise<void>Start Background Service.
| Param | Type |
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| options | { baseURL: string; basicAUTH: string; apiSuffix: string; deviceUUID: string; deviceType: string | null; macAddress: string | null; authPayload: { parameters: { header: string; }; }; } |
requestNotificationPermission()
requestNotificationPermission() => Promise<{ granted: boolean; }>Request notification permissions.
Returns: Promise<{ granted: boolean; }>
connectBleDevice(...)
connectBleDevice(options: { macAddress: string | null; }) => Promise<void>| Param | Type |
| ------------- | -------------------------------------------- |
| options | { macAddress: string | null; } |
isMqttClientConnected()
isMqttClientConnected() => Promise<boolean>Returns: Promise<boolean>
connectMqtt(...)
connectMqtt(options: { BrokerUrl: string; iOSBrokerUrl: string; username: string; password: string; }) => Promise<{ isMqttConnected: boolean; }>| Param | Type |
| ------------- | --------------------------------------------------------------------------------------------- |
| options | { BrokerUrl: string; iOSBrokerUrl: string; username: string; password: string; } |
Returns: Promise<{ isMqttConnected: boolean; }>
publishMessage(...)
publishMessage(options: { topicToPublish: string; payload: string; }) => Promise<{ isMessagePublished: boolean; }>| Param | Type |
| ------------- | --------------------------------------------------------- |
| options | { topicToPublish: string; payload: string; } |
Returns: Promise<{ isMessagePublished: boolean; }>
subscribeToNormalDLTopic(...)
subscribeToNormalDLTopic(options: { topicTOSubscribe: string; }) => Promise<{ isSubscriptionSuccess: boolean; }>| Param | Type |
| ------------- | ------------------------------------------ |
| options | { topicTOSubscribe: string; } |
Returns: Promise<{ isSubscriptionSuccess: boolean; }>
subscribeToOtherDLTopic(...)
subscribeToOtherDLTopic(options: { topicTOSubscribe: string; }) => Promise<{ isSubscriptionSuccess: boolean; }>| Param | Type |
| ------------- | ------------------------------------------ |
| options | { topicTOSubscribe: string; } |
Returns: Promise<{ isSubscriptionSuccess: boolean; }>
subscribeToAuthTopic(...)
subscribeToAuthTopic(options: { authTopicToSubscribe: string; }) => Promise<{ isSubscriptionSuccess: boolean; }>| Param | Type |
| ------------- | ---------------------------------------------- |
| options | { authTopicToSubscribe: string; } |
Returns: Promise<{ isSubscriptionSuccess: boolean; }>
disconnectMqttBroker()
disconnectMqttBroker() => Promise<{ isMqttBrokerDisconnected: boolean; }>Returns: Promise<{ isMqttBrokerDisconnected: boolean; }>
addListener(string, ...)
addListener(eventName: string, listenerFunc: (data: any) => void) => Promise<PluginListenerHandle>Listen for MQTT messages from native background service.
| Param | Type |
| ------------------ | ----------------------------------- |
| eventName | string |
| listenerFunc | (data: any) => void |
Returns: Promise<PluginListenerHandle>
Interfaces
PluginListenerHandle
| Prop | Type |
| ------------ | ----------------------------------------- |
| remove | () => Promise<void> |
