Question
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?
Answer
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
- Verify JavaScript Execution: First, confirm that basic JavaScript execution is working by testing with a simple console.log statement.
- Check Privileges: Ensure all required privileges are properly declared and granted.
- 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