0
所以我按照說明在https://crosswalk-project.org/documentation/embedding_crosswalk/extensions.html上創建了Crosswalk擴展。我的問題涉及擴展XWalkExtension類。Crosswalk - 如何在XWalkExtension類中獲取android應用程序上下文?
package org.crosswalkproject.sample;
import org.xwalk.core.XWalkExtension;
public class ExtensionEcho extends XWalkExtension {
private static String name = "echo";
private static String jsapi = "var echoListener = null;" +
"extension.setMessageListener(function(msg) {" +
" if (echoListener instanceof Function) {" +
" echoListener(msg);" + " };" + "});" +
"exports.echo = function (msg, callback) {" +
" echoListener = callback;" + " extension.postMessage(msg);" +
"};" + "exports.echoSync = function (msg) {" +
" return extension.internal.sendSyncMessage(msg);" + "};";
public ExtensionEcho() {
super(name, jsapi);
}
@Override
public void onMessage(int instanceID, String message) {
postMessage(instanceID, "From java: " + message);
}
@Override
public String onSyncMessage(int instanceID, String message) {
return "From java sync: " + message;
}
}
擴展XWalkExtension類時,如何獲取android應用程序上下文?因此,如果我想創建一個Toast消息,我可以傳入上下文。