I am making an app that needs to be run in the background. It is basically a reminder after every x hours, While I am on the app the app send the notification without any issue, but as soon as I get out of it, nothing is running anymore.
I am very new to Tizen development. Any help is appreciated. Here is my config.xml. Also, I do not have any service running as I do not know how to.
I have the app running, I tried running a service but I do not even know how to do that. So I ended up adding background-category in the config.xml.
<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets"
xmlns:tizen="http://tizen.org/ns/widgets"
id="http://yourdomain/Interval"
version="1.0.0"
viewmodes="maximized">
<tizen:application id="UmkARFYyuP.Interval" package="UmkARFYyuP" required_version="7.0"/>
<content src="index.html"/>
<feature name="http://tizen.org/feature/screen.size.all"/>
<icon src="icon.png"/>
<name>Interval</name>
<tizen:privilege name="http://tizen.org/privilege/power"/>
<tizen:privilege name="http://tizen.org/privilege/application.launch"/>
<tizen:privilege name="http://tizen.org/privilege/systemsettings"/>
<tizen:privilege name="http://tizen.org/privilege/alarm"/>
<tizen:privilege name="http://tizen.org/privilege/notification"/>
<tizen:profile name="wearable"/>
<tizen:background-category value="media" />
</widget>
Main.js
document.addEventListener('DOMContentLoaded', function () {
var taskForm = document.getElementById('taskForm');
var stopButton = document.getElementById('stopButton');
var message = document.getElementById('message');
var intervalId;
taskForm.addEventListener('submit', function (e) {
e.preventDefault();
if (intervalId) {
clearInterval(intervalId);
}
var taskName = document.getElementById('taskName').value;
var interval = parseInt(document.getElementById('interval').value);
var intervalMs = interval * 1000; // Convert to milliseconds
message.textContent = `Reminder for ${taskName} set every ${interval} seconds`;
intervalId = setInterval(function () {
try {
// Turn on the screen
tizen.power.turnScreenOn();
// Vibrate the device
navigator.vibrate(1000); // Vibrate for 1 second
// Create the notification properties
var notificationDict = {
content: `Time to do: ${taskName}`,
vibration: true,
iconPath: "icon.png" // Optional: Set a path to your app's icon
};
// Create and post the notification
var notification = new tizen.UserNotification('SIMPLE', 'Task Reminder', notificationDict);
tizen.notification.post(notification);
} catch (error) {
console.error("Error: " + error.message);
}
}, intervalMs);
});
stopButton.addEventListener('click', function () {
if (intervalId) {
clearInterval(intervalId);
message.textContent = 'Reminder stopped';
}
});
});
Index.html
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, user-scalable=no">
<title>Task Reminder</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="container">
<h1>Task Reminder</h1>
<form id="taskForm">
<label for="taskName">Task Name:</label>
<input type="text" id="taskName" required>
<label for="interval">Remind Every (seconds):</label>
<input type="number" id="interval" min="1" required>
<button type="submit">Start</button>
<button type="button" id="stopButton">Stop</button>
</form>
<p id="message"></p>
</div>
<script src="js/main.js"></script>
</body>
</html>