在仅包含样板 HTML 和以下 JavaScript 的应用程序中使用 Trigger.io 的条形码 API :
forge.barcode.scan(function (value) {
alert("You scanned: "+value);
});
我在日志中收到以下错误:
Forge Java 错误:RuntimeException:无法在未调用 Looper.prepare() 的线程内创建处理程序
完整的错误条目:
[INFO] D/Forge(1109):返回:{“content”:{“message”:“Forge Java 错误:RuntimeException:无法在未调用 Looper.prepare() 的线程内创建处理程序”“type” :"UNEXPECTED_FAILURE","subtype":null,"full_error":"java.lang.RuntimeException: 无法在 android.os.Handler 调用 Looper.prepare() 的线程内创建处理程序。(Handler.java: 197) 在 android.os.Handler.(Handler.java:111) 在 android.app.Dialog.(Dialog.java:107) 在 android.app.AlertDialog.(AlertDialog.java:114) 在 android.app.AlertDialog $Builder.create(AlertDialog.java:931) at android.app.AlertDialog$Builder.show(AlertDialog.java:950) at io.trigger.forge.android.modules.barcode.API.scan(API.java:68 ) 在 java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at io.trigger.forge.android.core.ForgeApp.callJavaFromJavaScript(ForgeApp.java:247) at io。 trigger.forge.android.core.ForgeJSBridge$1.run(ForgeJSBridge.java:17) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor .java:573) 在 java.lang.Thread.run(Thread.java:856)\n"},"callid":"35E46BC5-1C17-4354-B09B-BE67B5FCD513","status":"error"}ForgeJSBridge$1.run(ForgeJSBridge.java:17) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) at java. lang.Thread.run(Thread.java:856)\n"},"callid":"35E46BC5-1C17-4354-B09B-BE67B5FCD513","status":"error"}ForgeJSBridge$1.run(ForgeJSBridge.java:17) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) at java. lang.Thread.run(Thread.java:856)\n"},"callid":"35E46BC5-1C17-4354-B09B-BE67B5FCD513","status":"error"}
更新:
下面是我的代码:
文件config.json
{
"config_version": "2",
"name": "Scan to Web",
"author": "email@email.com",
"version": "0.1",
"platform_version": "v1.4",
"description": "An empty app created by default",
"modules": {
"logging": {
"level": "DEBUG"
},
"barcode": true,
"contact": true,
"file": true,
"is": true,
"media": true,
"prefs": true,
"request": {
"permissions": ["http://*/*", "https://*/*"]
},
"tools": true,
"reload": true
}
}
文件default.js
forge.barcode.scan(function (value) {
alert("You scanned: "+value);
});
文件index.html
<!DOCTYPE html>
<html>
<head>
<title>Hello World!</title>
<link rel="stylesheet" href="css/jquery.mobile-1.1.0.min.css" />
<script src="js/jquery-1.7.1.min.js"></script>
<script src="js/jquery.mobile-1.1.0.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>
<script type="text/javascript" src="js/default.js"></script>
</head>
<body>
<p>Hello world!</p>
</body>
</html>