Namespaces
Variants
Actions

ローカルデバイス機能を提供するため、MWS(Mobile Web Server)を使用する方法

Jump to: navigation, search
Archived.png
Archived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

The Mobile web server discontinued, as of February 2010. See below for more information.
Article Metadata

Article
Translated:
Last edited: hamishwillee (09 Aug 2012)

多くの WidSet/Widget アプリケーションは、ネイティブアプリケーションで可能な機能の多くをAPIとしてサポートしていないため、制限があります。例えば、以下のような機能が挙げられます。

  • GPSモジュールを使用して位置情報を取得する
  • 端末のカメラ機能を使って写真を撮る
  • Bluetooth接続
  • 電話帳(Contact)、Inboxフォルダ、外部アプリケーションへのアクセス
  • SMSの送信
  • その他

その簡単な解決法の1つは、これらの機能を提供するMobile Web Serverを使用することです。そのためには、いくつかのステップを踏む必要があります。

WidSet/Widgetから、MWS(Mobile Web Server)に接続する

下記に示す例は、MWSから情報を取得する方法です。

  • Widgetの例
function queryMWS()
{
// This code uses Prototype, but a standard javascript request will work just as well
new Ajax.Request("http://localhost/hello.py",
{
method: 'get',
asynchronous: 'false',
onSuccess: function(transport, json)
{
return true;
},
onFailure: function()
{
return false;
}
});
}
  • WidSetの例
void queryMWS()
{
// Prepare the URL.
String URL = "https://MWS_username:MWS_password@MWS_username.mymobilesite.net/hello.py";
 
// Fetch from the URL.
call(null, "httpLocalhost", "get", ["url" => URL], success, failure);
 
void success(Object state, Value ret)
{
setBubble(null, "The server successfully returned " + ret);
return;
}
 
void failure(Object state, String error)
{
setBubble(null, "Local server is not responding properly.");
return;
}
}

ローカルの端末機能を提供するため、MWSでpythonモジュールを使用する

MWS上で実行するpythonを取得するため、2つのファイルが必要です。

  • ht.acl

Invalid language.

You need to specify a language like this: <source lang="html4strict">...</source>

Supported languages for syntax highlighting:

4cs, 6502acme, 6502kickass, 6502tasm, 68000devpac, abap, actionscript, actionscript3, ada, algol68, apache, applescript, apt_sources, asm, asp, autoconf, autohotkey, autoit, avisynth, awk, bascomavr, bash, basic4gl, bf, bibtex, blitzbasic, bnf, boo, c, c_loadrunner, c_mac, caddcl, cadlisp, cfdg, cfm, chaiscript, cil, clojure, cmake, cobol, coffeescript, cpp, cpp-qt, csharp, css, cuesheet, d, dcs, delphi, diff, div, dos, dot, e, ecmascript, eiffel, email, epc, erlang, euphoria, f1, falcon, fo, fortran, freebasic, fsharp, gambas, gdb, genero, genie, gettext, glsl, gml, gnuplot, go, groovy, gwbasic, haskell, hicest, hq9plus, html4strict, html5, icon, idl, ini, inno, intercal, io, j, java, java5, javascript, jquery, kixtart, klonec, klonecpp, latex, lb, lisp, llvm, locobasic, logtalk, lolcode, lotusformulas, lotusscript, lscript, lsl2, lua, m68k, magiksf, make, mapbasic, matlab, mirc, mmix, modula2, modula3, mpasm, mxml, mysql, newlisp, nsis, oberon2, objc, objeck, ocaml, ocaml-brief, oobas, oracle11, oracle8, oxygene, oz, pascal, pcre, per, perl, perl6, pf, php, php-brief, pic16, pike, pixelbender, pli, plsql, postgresql, povray, powerbuilder, powershell, proftpd, progress, prolog, properties, providex, purebasic, pycon, python, q, qbasic, rails, rebol, reg, robots, rpmspec, rsplus, ruby, sas, scala, scheme, scilab, sdlbasic, smalltalk, smarty, sql, systemverilog, tcl, teraterm, text, thinbasic, tsql, typoscript, unicon, uscript, vala, vb, vbnet, verilog, vhdl, vim, visualfoxpro, visualprolog, whitespace, whois, winbatch, xbasic, xml, xorg_conf, xpp, yaml, z80, zxbasic


AddHandler mod_python .py
PythonHandler cam
PythonDebug On 
Options None
 
Order Deny,Allow
Allow from all
 
<FilesMatch "\.(pyc)$">
    Deny from all
</FilesMatch>
  • hello.py

Invalid language.

You need to specify a language like this: <source lang="html4strict">...</source>

Supported languages for syntax highlighting:

4cs, 6502acme, 6502kickass, 6502tasm, 68000devpac, abap, actionscript, actionscript3, ada, algol68, apache, applescript, apt_sources, asm, asp, autoconf, autohotkey, autoit, avisynth, awk, bascomavr, bash, basic4gl, bf, bibtex, blitzbasic, bnf, boo, c, c_loadrunner, c_mac, caddcl, cadlisp, cfdg, cfm, chaiscript, cil, clojure, cmake, cobol, coffeescript, cpp, cpp-qt, csharp, css, cuesheet, d, dcs, delphi, diff, div, dos, dot, e, ecmascript, eiffel, email, epc, erlang, euphoria, f1, falcon, fo, fortran, freebasic, fsharp, gambas, gdb, genero, genie, gettext, glsl, gml, gnuplot, go, groovy, gwbasic, haskell, hicest, hq9plus, html4strict, html5, icon, idl, ini, inno, intercal, io, j, java, java5, javascript, jquery, kixtart, klonec, klonecpp, latex, lb, lisp, llvm, locobasic, logtalk, lolcode, lotusformulas, lotusscript, lscript, lsl2, lua, m68k, magiksf, make, mapbasic, matlab, mirc, mmix, modula2, modula3, mpasm, mxml, mysql, newlisp, nsis, oberon2, objc, objeck, ocaml, ocaml-brief, oobas, oracle11, oracle8, oxygene, oz, pascal, pcre, per, perl, perl6, pf, php, php-brief, pic16, pike, pixelbender, pli, plsql, postgresql, povray, powerbuilder, powershell, proftpd, progress, prolog, properties, providex, purebasic, pycon, python, q, qbasic, rails, rebol, reg, robots, rpmspec, rsplus, ruby, sas, scala, scheme, scilab, sdlbasic, smalltalk, smarty, sql, systemverilog, tcl, teraterm, text, thinbasic, tsql, typoscript, unicon, uscript, vala, vb, vbnet, verilog, vhdl, vim, visualfoxpro, visualprolog, whitespace, whois, winbatch, xbasic, xml, xorg_conf, xpp, yaml, z80, zxbasic


def handler(req):
	from mod_python import apache
	import httplib

	try:
                #
                # Execute any python code here
                #
		req.write("Hello World")
		req.status = 200
		return apache.OK

	except Exception, e:
		req.status = 404
		return apache.OK

pythonモジュールを使用する方法の良い例は、Mobile Python Bookにて見つけることができます。

  • 現在の位置情報を取得するためにpythonを使用する例

Invalid language.

You need to specify a language like this: <source lang="html4strict">...</source>

Supported languages for syntax highlighting:

4cs, 6502acme, 6502kickass, 6502tasm, 68000devpac, abap, actionscript, actionscript3, ada, algol68, apache, applescript, apt_sources, asm, asp, autoconf, autohotkey, autoit, avisynth, awk, bascomavr, bash, basic4gl, bf, bibtex, blitzbasic, bnf, boo, c, c_loadrunner, c_mac, caddcl, cadlisp, cfdg, cfm, chaiscript, cil, clojure, cmake, cobol, coffeescript, cpp, cpp-qt, csharp, css, cuesheet, d, dcs, delphi, diff, div, dos, dot, e, ecmascript, eiffel, email, epc, erlang, euphoria, f1, falcon, fo, fortran, freebasic, fsharp, gambas, gdb, genero, genie, gettext, glsl, gml, gnuplot, go, groovy, gwbasic, haskell, hicest, hq9plus, html4strict, html5, icon, idl, ini, inno, intercal, io, j, java, java5, javascript, jquery, kixtart, klonec, klonecpp, latex, lb, lisp, llvm, locobasic, logtalk, lolcode, lotusformulas, lotusscript, lscript, lsl2, lua, m68k, magiksf, make, mapbasic, matlab, mirc, mmix, modula2, modula3, mpasm, mxml, mysql, newlisp, nsis, oberon2, objc, objeck, ocaml, ocaml-brief, oobas, oracle11, oracle8, oxygene, oz, pascal, pcre, per, perl, perl6, pf, php, php-brief, pic16, pike, pixelbender, pli, plsql, postgresql, povray, powerbuilder, powershell, proftpd, progress, prolog, properties, providex, purebasic, pycon, python, q, qbasic, rails, rebol, reg, robots, rpmspec, rsplus, ruby, sas, scala, scheme, scilab, sdlbasic, smalltalk, smarty, sql, systemverilog, tcl, teraterm, text, thinbasic, tsql, typoscript, unicon, uscript, vala, vb, vbnet, verilog, vhdl, vim, visualfoxpro, visualprolog, whitespace, whois, winbatch, xbasic, xml, xorg_conf, xpp, yaml, z80, zxbasic


def handler(req):

	from mod_python import apache
	import location
	import positioning

	req.content_type = 'text/xml'

	req.write("<?xml version='1.0' encoding='utf-8'?>")
	req.write("<twitnflick>")
	req.write("<modules count='" + str(len(positioning.modules())) + "' default='" + str(positioning.default_module()) + "'>")
	for n in range(0, len(positioning.modules())):
		req.write("<module id='" + str(positioning.modules()[n]['id']) + "'>")
		req.write("<name>" + positioning.modules()[n]['name'] + "</name>")
		req.write("<available>" + str(positioning.modules()[n]['available']) + "</available>")
		req.write("</module>")
	
	req.write("</modules>")	

	positioning.set_requestors([{"type":"service","format":"application","data":"test"}])
	gpspos = positioning.position()
	req.write("<position>")
	req.write("<latitude>" + str(gpspos['position']['latitude']) + "</latitude>")
	req.write("<longitude>" + str(gpspos['position']['longitude']) + "</longitude>")
	req.write("<altitude>" + str(gpspos['position']['altitude']) + "</altitude>")
	req.write("<horizontal_accuracy>" + str(gpspos['position']['horizontal_accuracy']) + "</horizontal_accuracy>")
	req.write("<vertical_accuracy>" + str(gpspos['position']['vertical_accuracy']) + "</vertical_accuracy>")
	req.write("</position>")

	req.write("</twitnflick>")

	return apache.OK
This page was last modified on 9 August 2012, at 08:15.
102 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved