How to execute JavaScript from Native C code in Tizen?

Original Created Mar 24, 2017 | Regeneration Apr 22, 2026

I'm trying to execute JavaScript code from a native Tizen application (written in C) but my function keeps failing. Here's the problematic code:

static Evas_Object* load_html_file(Evas_Object* parent)
{
    Evas *e_webview = evas_object_evas_get(parent);
    Evas_Object *browser = ewk_view_add(e_webview);
    Ewk_Settings *settings = ewk_view_settings_get(browser);
    ewk_settings_javascript_enabled_set(settings, EINA_TRUE);

    char* javaScript =
        "function setWallpaperSuccess() {}"
        "function setWallpaperError() {}"
        "function test() {"
        "    try {"
        "        tizen.systemsetting.setProperty(\"HOME_SCREEN\", \"file:///opt/usr/media/Downloads/2017-03-20_RiverofLife_1080x1920_no.jpg\", setWallpaperSuccess, setWallpaperError);"
        "    }"
        "    catch (error) {"
        "        console.log(\"Error: \" + error); return 'exceptionhappened';"
        "    } return 'thisworkedorwhat';"
        "}"
        "test();";
    ewk_view_script_execute(browser, javaScript, JScallback, NULL);
    elm_win_resize_object_add(parent, browser);
    evas_object_show(parent);
    evas_object_show(browser);
    return browser;
}

static void JScallback(Evas_Object* o, const char* result_value, void* user_data) {
    dlog_print(DLOG_INFO, LOG_TAG, "[scriptCallback] return value: %s\n", result_value);
}

The sdb dlog always prints:

I/My-Experiment-App (31448): [scriptCallback] return value: exceptionhappened

Here are the privileges declared in my TizenManifest.xml:

<privileges>
    <privilege>http://tizen.org/privilege/mediastorage</privilege>
    <privilege>http://tizen.org/privilege/network.get</privilege>
    <privilege>http://tizen.org/privilege/systemsettings</privilege>
    <privilege>http://tizen.org/privilege/internet</privilege>
    <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
    <privilege>http://tizen.org/privilege/externalstorage</privilege>
</privileges>

Could anyone help me understand why this is failing?

Problem Understanding

The JavaScript code is executing but failing in the try block, causing it to enter the catch block and return 'exceptionhappened'. This indicates that the tizen.systemsetting.setProperty() function is not working as expected.

Solution Methods

  1. Verify JavaScript Execution: First, confirm that basic JavaScript execution is working by testing with a simple console.log statement.
  2. Check Privileges: Ensure all required privileges are properly declared and granted.
  3. Debug the System Setting API: Test the systemsetting API with simpler parameters to isolate the issue.

Code Examples

Here's a simplified test to verify JavaScript execution:

char* testScript = 
    "function test() {"
    "    console.log('JavaScript is working!');"
    "    return 'success';"
    "}"
    "test();";
ewk_view_script_execute(browser, testScript, JScallback, NULL);

Additional Tips

  • Make sure the file path you're trying to use exists and is accessible
  • Verify that the systemsetting API is supported on your Tizen version
  • Check the official documentation for any known limitations of the systemsetting API

Customize your cookie preferences

You can enable or disable non-essential cookies. Essential cookies are always on to ensure the site works properly and to keep you signed in.

Necessary

These cookies are necessary for the website to function properly and cannot be switched off. They help with things like logging in and setting your privacy preferences.

Always on

Analytics

These cookies help us improve the site by tracking which pages are most popular and how visitors move around the site.

Enable analytics cookies
Public Forum Public Forum
Employees only. Please sign in with your company account.