在人行横道上,js无法“改变”或“确认”

时间:2016-05-19 01:04:32

标签: android html5 crosswalk

Crosswalk 16.45.421.19

我在项目中使用crosswalk作为库,但是当我在html中调用js函数'alert'时,会出现一些错误。

05-17 16:12:27.136: E/chromium(2559): [ERROR:xwalk_autofill_client.cc(172)]                         Not implemented reached in virtual void          xwalk::XWalkAutofillClient::OnFirstUserGestureObserved()
05-17 16:12:27.251: I/chromium(2559): [INFO:CONSOLE(376)] "exec() is calledSmartdotTelephone.deviceInfo", source: file:///android_asset/www/common/mau/MDHAdapter.js (376)
05-17 16:12:27.271: W/ResourceType(2559): No package identifier when getting value for resource number 0x00000000
05-17 16:12:27.271: W/System.err(2559): android.content.res.Resources$NotFoundException: String resource ID #0x0
05-17 16:12:27.271: W/System.err(2559):     at android.content.res.Resources.getText(Resources.java:319)
05-17 16:12:27.271: W/System.err(2559):     at android.content.res.Resources.getString(Resources.java:405)
05-17 16:12:27.271: W/System.err(2559):     at android.content.Context.getString(Context.java:382)
05-17 16:12:27.271: W/System.err(2559):     at org.xwalk.core.internal.XWalkUIClientInternal.onJsAlert(XWalkUIClientInternal.java:390)
05-17 16:12:27.271: W/System.err(2559):     at org.xwalk.core.internal.XWalkUIClientInternal.onJavascriptModalDialog(XWalkUIClientInternal.java:166)
05-17 16:12:27.271: W/System.err(2559):     at org.xwalk.core.internal.XWalkContentsClientBridge.handleJsAlert(XWalkContentsClientBridge.java:715)
05-17 16:12:27.271: W/System.err(2559):     at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
05-17 16:12:27.271: W/System.err(2559):     at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:53)
05-17 16:12:27.271: W/System.err(2559):     at android.os.Handler.dispatchMessage(Handler.java:102)
05-17 16:12:27.271: W/System.err(2559):     at android.os.Looper.loop(Looper.java:135)
05-17 16:12:27.271: W/System.err(2559):     at android.app.ActivityThread.main(ActivityThread.java:5423)
05-17 16:12:27.271: W/System.err(2559):     at java.lang.reflect.Method.invoke(Native Method)
05-17 16:12:27.271: W/System.err(2559):     at java.lang.reflect.Method.invoke(Method.java:372)
05-17 16:12:27.271: W/System.err(2559):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:947)
05-17 16:12:27.271: W/System.err(2559):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:742)
05-17 16:12:27.271: A/chromium(2559): [FATAL:jni_android.cc(249)] Check failed: false. Please include Java exception stack in crash report

我在XWalkUIClientInternal.java中看到了人行横道的来源

@XWalkAPI
public boolean onJsAlert(XWalkViewInternal view, String url, String message,
        XWalkJavascriptResultInternal result) {
    final XWalkJavascriptResultInternal fResult = result;
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(mContext);
    dialogBuilder.setTitle(mContext.getString(R.string.js_alert_title))
            .setMessage(message)
            .setCancelable(true)
            .setPositiveButton(mContext.getString(android.R.string.ok),
                    new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    fResult.confirm();
                    dialog.dismiss();
                }
            })
            .setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
                    fResult.cancel();
                }
            });
    mDialog = dialogBuilder.create();
    mDialog.show();
    return false;
}

R.string.js_alert_title是人行横道的资源ID,它不是我项目中的本地资源ID,为什么人行横道不使用动态加载本地资源进行警报功能,以及如何重新启动?

1 个答案:

答案 0 :(得分:0)

Crosswalk在调用js'alert'功能方面效果很好。 例如,assets文件夹中有一个js_java_interaction.html:

import random as rnd
from numpy import *

pat_number=3
neu_per_pat=10
neu_number=4096
overlap=0.1

#------------ check if the setting is correct ------------------------
b=(pat_number-1)*(neu_per_pat-overlap*neu_per_pat)
a=neu_number-neu_per_pat -b

max_num_pat=(neu_number-neu_per_pat)/(neu_per_pat-overlap*neu_per_pat)+1
print "--------------------------------"
print neu_number, " total neurons, ", neu_per_pat, " active neurons per pattern. "
print "Overlap between patterns ",overlap, ", the max number of pattern is",max_num_pat
print "--------------------------------"

if a <0:
    print "can't generate that many pattern"
    print "- decrease the number of pattern or increase the overlap"

#---------------------------------------------------------------------

pool= arange(0,neu_number-1)


#creating the first pattern
patterns = {}  #patterns are stored into a dictionary
patterns['0']=rnd.sample(pool , neu_per_pat)  # Choose the elements of the first pattern
print 'patterns[0]',patterns['0']

#fix the overlapping neurons -- here we assume they are the same for all the patterns 
c=int(overlap*neu_per_pat)
print "overlap*neu_per_pat",c
overlapped_neus=rnd.sample(patterns['0'] , c)

#producing the other N-1 patterns
used_neurons=patterns['0']
print 'used_neurons',used_neurons

for pat in range(1,pat_number):

    remaining_neu1 = setdiff1d(pool,used_neurons)
    patterns['%s' % pat]=rnd.sample(remaining_neu1 , neu_per_pat-c)
    patterns['%s' % pat]+=overlapped_neus
    used_neurons+=patterns['%s' % pat]
    print 'used_neurons',used_neurons
    print 'patterns[0]',patterns['0']

print 'patterns[0]',patterns['0']
print 'patterns[1]',patterns['1']
print 'patterns[2]',patterns['2']

在您的活动中加载html: <html> <script type="text/javascript"> function alertMessage(message) { alert(message) } </script> Java-Javascript Interaction In Android </html>

加载后,请使用evaluateJavascript()API:

mXWalkView.load("file:///android_asset/js_java_interaction.html", null);