Languages

Menu
Sites
Language
Register protocol handler in Tizen

Hi All, 

How i can register and manage a protocol handler in tizen? i want to use it to invoke functions using the javascript bridge :)

 

Nello

Edited by: Brock Boland on 17 Mar, 2014 Reason: Paragraph tags added automatically from tizen_format_fix module.

Responses

2 Replies
Rafal Lelusz
Hello Nello, To register/unregister a custom protocol handler use window.navigator.registerProtocolHandler(protocol, uri, title); and window.navigator.unregisterProtocolHandler(protocol, uri); methods. They are part of HTML5 specification. please refer to documentation: http://www.whatwg.org/specs/web-apps/current-work/#custom-handlers https://developer.mozilla.org/en-US/docs/Web/API/navigator.registerProtocolHandler http://dev.opera.com/articles/view/html5-custom-protocol-and-content-handlers/

Example:

file register-protocol-handler.html
<!DOCTYPE HTML>
<html>
<body>
<p>This test makes sure that navigator.registerProtocolHandler throws the proper exceptions and has no-op default implementation.</p>
<pre id="console"></pre>

<script>
function log(str){
    var elem = document.getElementById("log");
    var current_str = elem.innerHTML.substring(0,1023);
    elem.innerHTML = str + "</br>" + current_str;
}

function get_protocol_url(){
    //var protocol_url = "http://" + window.location.host + "/protocol_result.php?test=%s";
    var protocol_url = "protocol_result.php?test=%s";
    return protocol_url;
}

function register() {
// Test that the API has default no-op implementation.
if (window.navigator.registerProtocolHandler)
    log('Pass: window.navigator.registerProtocolHandler is defined.');
else
    log('Fail: window.navigator.registerProtocolHandler is not defined.');
	var succeeded = true;
	try {
	    window.navigator.registerProtocolHandler('web+a', get_protocol_url(), "Test App Title");
	} catch (e) {
	    succeeded = false;
        log(e);
	}
	
	if (succeeded)
	    log('Pass: Valid call succeeded.');
	else
	    log('Fail: Invalid call did not succeed.');
}

function unregister() {
	var succeeded = true;
	try {
	    window.navigator.unregisterProtocolHandler('web+a', get_protocol_url());
	} catch (e) {
        succeeded = false;
        log(e);
	}
	
	if (succeeded)
	    log('Pass: Valid call succeeded.');
	else
	    log('Fail: Invalid call did not succeed.');
}

function isregister() {
	var succeeded = true;
	try {
	    log(window.navigator.isProtocolHandlerRegistered('web+a', get_protocol_url() ));
	} catch (e) {
	    log(e);
	}
}
</script>

<input type="button" value="register" onClick="register()" />
<input type="button" value="unregister" onClick="unregister()" />
<input type="button" value="isregister" onClick="isregister()" />

<a href="web+a://test_parameter_of_protocol" />Test Click</a>
</br>
<div id="log" style="width:99%; background-color:EEE;"></div>
</body>
</html>
file protocol_result.php
<!DOCTYPE html>
<html>
<body>

=== This is custom protocol ===</span></br>";
echo "<span>==================================================</span></br>";
echo "<span> ".$_GET["test"]."</span></br>";
echo "<span>==================================================</span></br>";
?>

</body>
</html>
Guyllaume Doyer

Hello Rafael,

I just tested this on Tizen. The registerProtocolHandler method is defined but does not seem to produce anything.

Have you tried to register a protocol handler on Tizen? Does it work?

Did someone else tried to play with this on Tizen?