-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Tizen/Web] Launch native service in web application
This patch launchs image classification offloading service in web application. Signed-off-by: Yelin Jeong <[email protected]>
- Loading branch information
Showing
2 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
* @author Yelin Jeong <[email protected]> | ||
*/ | ||
|
||
let gServiceAppId = "EQmf4iSfpX.imageclassificationoffloadingservice"; | ||
|
||
/** | ||
* Get currently used network type | ||
* @returns the network type | ||
|
@@ -72,3 +74,61 @@ export function loadLabelInfo() { | |
const labelList = fHandle.readString(); | ||
return labelList.split("\n"); | ||
} | ||
|
||
function launchServiceApp() { | ||
function onSuccess() { | ||
console.log("Service App launched successfully"); | ||
} | ||
|
||
function onError(err) { | ||
console.error("Service App launch failed", err); | ||
} | ||
|
||
try { | ||
console.log("Launching [" + gServiceAppId + "] ..."); | ||
tizen.application.launch(gServiceAppId, onSuccess, onError); | ||
} catch (exc) { | ||
console.error("Exception while launching HybridServiceApp: " + exc.message); | ||
} | ||
} | ||
|
||
function onGetAppsContextSuccess(contexts) { | ||
let i = 0; | ||
let appInfo = null; | ||
|
||
for (i = 0; i < contexts.length; i = i + 1) { | ||
try { | ||
appInfo = tizen.application.getAppInfo(contexts[i].appId); | ||
} catch (exc) { | ||
console.error("Exception while getting application info " + exc.message); | ||
} | ||
|
||
if (appInfo.id === gServiceAppId) { | ||
break; | ||
} | ||
} | ||
|
||
if (i >= contexts.length) { | ||
console.log("Service App not found, Trying to launch service app"); | ||
launchServiceApp(); | ||
} | ||
} | ||
|
||
function onGetAppsContextError(err) { | ||
console.error("getAppsContext exc", err); | ||
} | ||
|
||
/** | ||
* Starts obtaining information about applications | ||
* that are currently running on a device. | ||
*/ | ||
export function startHybridService() { | ||
try { | ||
tizen.application.getAppsContext( | ||
onGetAppsContextSuccess, | ||
onGetAppsContextError, | ||
); | ||
} catch (e) { | ||
console.log("Get AppContext failed, " + e); | ||
} | ||
} |