언어 설정

Menu
Sites
Language
tizen.systeminfo.getPropertyValue("LOCALE"... does not work correctly

Hello,

I am quite new at developing Tizen apps for the gear watchs and there are some things which I still don't understand so I'd lke to ask for your help in this matter.

I am trying to get the language of the gear watch of the user with this code:

tizen.systeminfo.getPropertyValue("LOCALE", function(device){
            if(device.language=="en_US")
                console.log("English");
            else
                console.log("No english");
        }, function(e){
            console.log(JSON.stringify(e));
        });

 

The first time I install the app on the watch and I run the app, everything runs correctly device.language has the value "en_US". However, when I close the app and I open it again and the rest of the times, I get the following error from the "console.log(JSON.stringify(e)":

{"code":-1,"name":"UnknownError","message":"Error when retrieving system setting information: -5"}

Does anybody have any idea about how to do this? Thank you.

Responses

4 댓글
Armaan-Ul- Islam

Sharing a code sample with you. I tried this app relaunching several times, even rebooted the device. Seems No problem here or no error thrown. Tried on both emulator and device. You can add the 'system' privilege in config.xml

 

New > Template > Wearable > Web Application > Basic UI

Then replace the main.js with this code and deploy to device:

main.js

window.onload = function () {
    // TODO:: Do your initialization job

    // add eventListener for tizenhwkey
    document.addEventListener('tizenhwkey', function(e) {
        if(e.keyName === "back") {
    		try {
			    tizen.application.getCurrentApplication().exit();
			} catch (ignore) {
			}
		}
	});

    // Sample code
    var textbox = document.querySelector('.contents');
    textbox.addEventListener("click", function(){
    	var box = document.querySelector('#textbox');
    	tizen.systeminfo.getPropertyValue("LOCALE", function(device){
    		
    		box.innerHTML = (box.innerHTML === "Basic") ? device.language : "Language";
            if(device.language === "en_US"){
                console.log("English");}
            else{
                console.log("No english");}
            
        }, function(e){
        	box.innerHTML = "Error";
            console.log(JSON.stringify(e));
        });   	
    });
    
};

 

Frank

Hi Armaan,

Thank you for your reply. I have tried and it indeed works. However, it is necessary to click at least once on the screen to get the information. I would like getPropertyValue to be executed right away when the apps starts: this is when this issue shows up.

I have also tried with addEventListener("DOMContentLoaded"    with no luck. Do you have any idea?

Armaan-Ul- Islam

The code is already on window.onload, you need to do nothing to retreive the data on launch. Just get rid of the eventListener. Replace main.js with this one:

( I tested the app for different cases, works flawlessly )

window.onload = function () {
   document.addEventListener('tizenhwkey', function(e) {
        if(e.keyName === "back") {
            try {
                tizen.application.getCurrentApplication().exit();
			} catch (ignore) {
			}
		}
	});
 
    var box = document.querySelector('#textbox');
    tizen.systeminfo.getPropertyValue("LOCALE", function(device){

        box.innerHTML = (box.innerHTML === "Language") ? device.language : "Language";
        if(device.language === "en_US"){
           console.log("English");}
        else{
            console.log("No english");}       
        }, function(e){

        box.innerHTML = "Error";
        console.log(JSON.stringify(e));
    });
    
};

 

Armaan-Ul- Islam

Hello Frank,

What's the current stat now ? Is the app giving you the 'device.language' value without exceptions now ?