Question
I'm trying to create a simple Tizen watch application where clicking on text should launch the messaging app. However, my implementation isn't working. Here's my code:
index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="css/style.css">
<script src="js/main.js"></script>
</head>
<body>
<div id="page">
<p id="para">Launch Messaging</p>
</div>
</body>
</html>
main.js:
(function() {
function launchApp() {
tizen.application.launch("com.samsung.message");
}
function init() {
window.getElementById('page').addEventListener('click', launchApp);
}
window.onload = init();
}());
What am I missing? Why isn't the click event working to launch the messaging app?
Answer
Problem Understanding
The issue appears to be with the event listener setup and application launch implementation. There are several potential problems:
- The event listener might not be properly attached
- The application ID might be incorrect
- The necessary privilege might be missing in config.xml
Solution Methods
-
Verify Application ID: First, confirm the correct application ID for the messaging app by listing all installed applications.
-
Check Privileges: Ensure your config.xml includes the required privilege for launching applications.
-
Proper Event Handling: Correct the event listener implementation and add error handling.
Code Examples
Listing installed applications:
function onListInstalledApps(applications) {
for (var i = 0; i < applications.length; i++) {
console.log("ID: " + applications[i].id);
}
}
tizen.application.getAppsInfo(onListInstalledApps);
Corrected main.js with error handling:
(function() {
function launchApp() {
try {
tizen.application.launch("com.samsung.message");
} catch (error) {
console.error("Failed to launch app: " + error.message);
}
}
function init() {
document.getElementById('page').addEventListener('click', launchApp);
}
window.onload = init;
}());
Additional Tips
-
Make sure your config.xml includes:
<privilege>http://tizen.org/privilege/application.launch</privilege> -
Use
documentinstead ofwindowfor DOM operations. -
Don't call
init()directly in window.onload - just assign the function reference. -
Test your application on an actual device as some features might not work in the emulator.