QPython3,安卓6.0;我猜JS不能实例化 var droid = new Android(); 有什么提示可以解决问题吗?
Python 代码(两种情况都一样!):
import android
droid=android.Android()
droid.webViewShow('file:///storage/emulated/0/qpython/scripts3/test10_le_HTMLGUI_01.html')
while True:
result=droid.eventWaitFor('sag').result
droid.ttsSpeak(result['data'])
HTML 代码:test10_le_HTMLGUI_01.html(案例 1):
<html>
<head>
<title>Text To Speech</title>
<script>
var n = prompt("Hello JavaScript","");
var droid = new Android();
var speak = function() {
var n = prompt("Hello JavaScript","");
droid.eventPost("sag", document.getElementById("sag").value, 1);
}
</script>
</head>
<body>
<form onsubmit="speak(); return false;">
<label for="sag">What is your message?</label>
<input type="text" id="sag" />
<input type="submit" value="Speak" />
</form>
</body>
</html>
HTML 代码(案例 2):
<html>
<head>
<title>Text To Speech</title>
<script>
var droid = new Android();
var n = prompt("Hello JavaScript","");
var speak = function() {
var n = prompt("Hello JavaScript","");
droid.eventPost("sag", document.getElementById("sag").value, 1);
}
</script>
</head>
<body>
<form onsubmit="speak(); return false;">
<label for="sag">What is your message?</label>
<input type="text" id="sag" />
<input type="submit" value="Speak" />
</form>
</body>
</html>
而在案例 1 中,提示(“Hello JavaScript”,“”);执行它不是在情况2!
QPython3 (Android 6) SL4A eventPost() 和 eventWaitFor() 在以下示例中工作正常(有关添加信息,请参阅 http://www.mithril.com.au/android/doc/):
import android, time
droid=android.Android()
t = 'Geschafft!'
print('debug 1')
droid.eventPost('Event1', t, 1)
print('debug 2')
print('debug 3')
result=droid.eventWaitFor('Event1').result
droid.ttsSpeak(result['data'])
print('debug 4')
print(result['data'])
证明:如果您注释掉 droid.eventPost('Event1', t, 1) 行,那么 eventWaitFor() 将永远阻塞!
也许我们在QPython3 webViewShow 中有类似的问题 - 脚本没有接收数据 ,并且在https://stackoverflow.com/questions/36478310/qpython-webview-javascript-android-object
问候古斯塔夫 (2017-03-21)