Many times you may be working on an app that needs to show some notifications to users as activities occur – even when a different app is on the foreground. E.g an app that reminds you to take your meds every 4 hours. Sometimes, you may need your gear app to launch its host counterpart (even when it is not currently running), and vice versa. This post provides simple sample code to wake up your gear app and bring it to the foreground . It also covers how to autolaunch your host side app from the gear app .
Use the Tizen Application Launch Command.
1.) Note your Application id. you can find this in your config.xml file like this
<tizen:application id="ZeGjfywvaa.gearapp" package="ZeGjfywvaa" required_version="2.2"/>
2.) Use the tizen.application.launch command to launch your app from background to foreground. This command takes your app id (above) as an argument .
tizen.application.launch("ZeGjfywvaa.gearapp", onsuccess);
function onsuccess() {
console.log("Application launched successfully");
}
Note that you can call this in some background process that evaluates your notification condition e.g a setInterval timer .
3.) Add the necessary priviledges to your config.xml
<tizen:privilege name="http://tizen.org/privilege/application.launch"/> <tizen:setting background-support="enable" encryption="disable" hwkey-event="enable"/>
The first privilege allows you perform an application launch (from background to foreground) . The second allows your app to keep running in the background. e.g code that evaluates your notification condition.
See Also : How to Store Data in your Gear 2 Apps
Note: For best user experience always ensure your UI flow gives the user a direct and easy way to dismiss the notification. Feel free to share how you have used this snippet in the comments below.
One More thing – You can pass data when you Launch Your Gear App
Sometimes when you use the launch command to bring your gear app to the foreground, you may want a particular page to show up rather than the default homepage. Also when you launch a different app, you may also want to pass some data to it. This can be done using the appControl Object.
var appControlData = [new tizen.ApplicationControlData("values", ["Bango", "Bingo"])] ;
var appControl = new tizen.ApplicationControl( "http://tizen.org/appcontrol/operation/pick", null, "image/jpeg", null, appControlData);
tizen.application.launchAppControl(
appControl,
appid,
function() { console.log("launch application control succeed"); },
function(e) {console.log("launch application control failed. reason: " + e.message);
},appControlReplyCallback );
To read the data passed to an app when it is launched, you use the getRequestedAppControl() method.
var reqAppControl = tizen.application.getCurrentApplication().getRequestedAppControl(); if (reqAppControl) {
alert("Requester AppID : " + reqAppControl.appControl.operation );
var data = reqAppControl.appControl.data alert("Requester AppID : " + data[0].value[0]); }
More detail on this can be found in the tizen sdk help reference
Tizen Wearable Web App Programming > API References > Device API Reference > Application .
AutoLaunch Your App
Update : it appears you can only autolaunch the host side app from your gear app but NOT the gear app from the host app.
You can configure your host side app to be launched whenever a connection request is made. If you recall in the first tutorial, we use the SAP protocol in the HelloAccessory Tutorial to establish a connection between the gear and host apps. SAP runs on the host app, and “pipes” connection requests from the gear to the host app. I guess this is why it is able to autolaunch the host app in the event that it is closed. Given that there isnt an equivalent of SAP running on gear (for now), it is unclear if this autolaunch function works vice versa.
To autolaunch the Host app from your gear, you should modify the accessoryservices.xml file found in the Gear Project folder (res/xml/accessoryservices.xml) and include the autolaunchid (its full package name found in androidmanifest.xml) for the host app.
<serviceProfile
id="/system/helloaccessory"
name="helloaccessory"
role="consumer"
autoLaunchAppId = com.samsung.android.example.helloaccessoryprovider"
version="2.0" >
See Also : Create rad touch gestures for your gear 2 apps using Hammer.js




![Getting Accelerometer Data in Javascript for your Gear 2 Apps [Sample Code]](/blog/wp-content/uploads/2014/06/DSC_0010-e1403604089758-150x150.webp)

